2015-11-04 89 views
1

我有一个对象数组,我使用st-table指令显示。更新内容后更新智能表

我使用对象中某个字段的值来过滤表。 问题是,一旦这些对象中的某个字段的值被更改,则不会执行过滤。

我相信它的原因是smart-table监视数组的长度,但不会深入比较以查看任何对象内部的值是否发生更改。

我能做些什么来解决这个问题?

编辑:添加代码:

angular.module('myApp', ['smart-table']) 
    .controller('mainCtrl', ['$scope', '$timeout', 
    function ($scope, $timeout) { 

     $scope.rowCollection = [ 
     { 
      name: "sth odd", 
      number: 1 
     }, 
     { 
      name: "sth even", 
      number: 1 
     } 
     ]; 

     $scope.displayedCollection = [].concat($scope.rowCollection); 

     function changeNumber(){ 
      $timeout(function(){ 
      $scope.rowCollection[1].number = $scope.rowCollection[1].number === 1 ? 2 : 1; 
      changeNumber(); 
      }, 1000); 
     } 

     changeNumber(); 


    } 
]); 

http://plnkr.co/edit/IVYy5WrsiEJSRXZCqY9z?p=preview

注意,当您搜索如何如数字“2”,没有更新的观点,即使第二项的属性有时是“2 “而且有时候不是。

+0

你能发表一些代码来重现这个问题吗? – svarog

+0

@svarog,添加了代码和工作示例 – kihu

回答

2

为您找到了解决方案,而不是使用st-search使用普通的ng-model,然后按ng模型值进行过滤。然后在ng-repeat过滤器由值

所以不是这个

<input st-search="number" placeholder="search for number" class="input-sm form-control" type="search"/> 
... 

<tr ng-repeat="row in displayedCollection"> 
    <td>{{row.name}}</td> 
    <td>{{row.number}}</td> 
</tr> 

做到这一点

<input ng-model="searchMe" placeholder="search for number" class="input-sm form-control" type="search"/> 
.... 

<tr ng-repeat="row in filterd = (displayedCollection | filter: searchMe)"> 
    <td>{{row.name}}</td> 
    <td>{{row.number}}</td> 
</tr> 

这里有一个plunker,进入2,看看它是如何在每次重做操作的过滤

0

要刷新智能表,你可以添加或删除项目,因为你知道或使用新的阵列..所以只需重新创建阵列

$scope.rowCollection = [].concat($scope.rowCollection);