1

我一直在挖掘 SO 和其他帖子,但无法使其工作。我有一个列表,我用 ng-repeat 对其进行迭代并对其应用一些过滤器。当列表的索引未更改时,ui-sortable 可以很好地工作,但只要索引更改(通过过滤器),过滤后的列表就不会反映排序顺序。这是jsfiddle:http: //jsfiddle.net/hKYWr/1996/

<div ng:controller="controller">
    <input type="text" class="form-control" ng-model="query" placeholder="Search...">
    <div ui:sortable ng:model="filteredList">
        <div ng:repeat="item in filteredList = (list | filter:query | limitTo:4)" class="item">{{item.val}}</div>
    </div>
    <hr />
    <div ng:repeat="item in filteredList">{{item.val}}</div>
</div>

<script src="http://code.angularjs.org/1.0.2/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui.min.js"></script>`

var myapp = angular.module('myapp', ['ui']);
myapp.controller('controller', function ($scope) {
    $scope.list = [{val:"one",count:1}, {val:"two",count:2}, {val:"three",count:3},{val:"four",count:4}];
});

angular.bootstrap(document, ['myapp']);

我希望我的过滤列表在我进行排序后立即得到更新。有什么帮助吗?

4

0 回答 0