我正在使用bootstrap table和ngStorage。我試圖做的是將表搜索保存到本地存儲並在刷新表後重新找回。 這是我簡單的代碼:
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>
,並通過這個代碼,我越來越變回來,當我點擊按鈕加載篩選。您可以在Load 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的搜索BS表,但不觸發。
正在檢索文本,問題是我無法推回這個文本來搜索 – Anton
你可以發佈你的搜索代碼 –
你嘗試過text.push($ scope.storage.text ); –