从 $localstorage 中检索变量
Retrieve variable from $localstorage
我正在使用 bootstrap table 和 ngStorage。我想做的是将搜索保存到本地存储并在 table 刷新后将其取回。
这是我的简单代码:
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>
通过这段代码,当我点击加载过滤器按钮时,我得到了变量。您可以在加载 Table 按钮的右侧看到它。
但是当我试图将这个变量推送到搜索时。
$scope.loadSearch = function() {
$('#table').on('search.bs.table', function (e, text){
text.push($scope.storage);
console.log($scope.storage)
});
$scope.data = $scope.storage;
};
我的功能根本不起作用。如果有人能解释我的错误在哪里,我将不胜感激?
My plunker, where you can see the problem
With this plunker,可以把localstorage中的值放到search bs中table,但是不触发。
$scope.storage = $locastorage
将整个 $localstorage
对象分配给变量。我不认为这是你想要做的。
要读取 $localstorage
的特定变量,请执行
$scope.myvar = $localstorage.localvar
此外 text.push($scope.storage);
没有分配任何东西给 $scope.storage
。 myarray.push(myvar)
将 myvar
添加到 myarray
把东西放进$scope.storage
做
$scope.storage = text
$scope.storage.mykey = text
将文本保存到本地存储
$scope.storage.text = text;
然后检索文本
$scope.data = $scope.storage.text
我正在使用 bootstrap table 和 ngStorage。我想做的是将搜索保存到本地存储并在 table 刷新后将其取回。 这是我的简单代码:
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>
通过这段代码,当我点击加载过滤器按钮时,我得到了变量。您可以在加载 Table 按钮的右侧看到它。
但是当我试图将这个变量推送到搜索时。
$scope.loadSearch = function() {
$('#table').on('search.bs.table', function (e, text){
text.push($scope.storage);
console.log($scope.storage)
});
$scope.data = $scope.storage;
};
我的功能根本不起作用。如果有人能解释我的错误在哪里,我将不胜感激?
My plunker, where you can see the problem
With this plunker,可以把localstorage中的值放到search bs中table,但是不触发。
$scope.storage = $locastorage
将整个 $localstorage
对象分配给变量。我不认为这是你想要做的。
要读取 $localstorage
的特定变量,请执行
$scope.myvar = $localstorage.localvar
此外 text.push($scope.storage);
没有分配任何东西给 $scope.storage
。 myarray.push(myvar)
将 myvar
添加到 myarray
把东西放进$scope.storage
做
$scope.storage = text
$scope.storage.mykey = text
将文本保存到本地存储
$scope.storage.text = text;
然后检索文本
$scope.data = $scope.storage.text