检索$ localStorage的变量 [英] Retrieve variable from $localstorage
问题描述
我与举表并ngStorage工作。我试图做的是保存的搜索到本地存储和检索回表已被刷新后。
这是我简单的code:
I'm working with bootstrap table and ngStorage. What I'm trying to do is to save search to local storage and retrieve it back after table has been refreshed. This is my simple code:
JS
//Assigning $localstorage to $session.storage
$scope.storage = $localStorage;
$scope.saveSearch = function () {
$scope.child = prompt('Set your filter.');
$('#table').on('search.bs.table', function (e, text){
$scope.storage = text
});
};
$scope.loadSearch = function() {
$scope.data = $scope.storage;
};
HTML
<div id="toolbar">
<div style="display: -webkit-box">
<button id="new" class="btn btn-default">New</button>
<button id="edit" class="btn btn-default">Edit</button>
<button id="remove" class="btn btn-default">Delete</button>
<button class="btn btn-default " ng-click="saveSearch()">Save Filter</button>
<button class="btn btn-default " ng-click = "loadSearch()">Load Filter</button>
<button id="button" class="btn-primary btn">Load Table</button>
<pre>{{data}}</pre></div>
</div>
table id="table"
class="table-striped"
data-toggle="table"
data-toolbar="#toolbar"
data-search="true"
data-show-columns="true"
data-show-export="true"
data-filter-control="true"
data-events="operateEvents"
data-formatter="operateFormatter"
data-response-handler="responseHandler"
>
</table>
和通过这个code我越来越变回来,当我点击按钮加载筛选器。你可以看到,在负载表按钮的右侧。
and thru this code I'm getting variable back, when I click on button Load Filter. You can see that on the right side of Load Table button.
但是,当我试图把这个变量来搜索。
But when I'm trying to push this variable to search.
$scope.loadSearch = function() {
$('#table').on('search.bs.table', function (e, text){
text.push($scope.storage);
console.log($scope.storage)
});
$scope.data = $scope.storage;
};
我的功能不能在所有工作。我AP preciate如果哪里是我的错任何人都可以解释我?
My function doesn't work at all. I appreciate if anybody could explain me where is my mistake?
有了这个plunker ,可以把价值从localStorage的搜索BS表,但它不触发。
With this plunker, you can put value from localstorage to search bs table, but it is not triggering.
推荐答案
$ scope.storage = $ locastorage
分配整个 $ localStorage的
对象变量。我不认为这是你想要做的事情。
$scope.storage = $locastorage
assigns the whole $localstorage
Object to the Variable. I don't think that this is what you want to do.
要读取的特定变量 $ localStorage的
不要
$scope.myvar = $localstorage.localvar
此外 text.push($ scope.storage);
不分配任何 $ scope.storage
。 myarray.push(MYVAR)
补充 MYVAR
到 myarray中
Furthermore text.push($scope.storage);
doesn't assign anything to $scope.storage
. myarray.push(myvar)
adds myvar
to myarray
要东西放在 $ scope.storage
不要
-
$ scope.storage =文本
-
$ scope.storage.mykey =文本
$scope.storage = text
$scope.storage.mykey = text
这篇关于检索$ localStorage的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!