ng-repeat with track by和filter and orderBy not working [英] ng-repeat with track by and filter and orderBy not working

查看:71
本文介绍了ng-repeat with track by和filter and orderBy not working的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码。

http:// jsfiddle .net / 0tgL7u6e /

JavaScript

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.nameFilter = '';
    $scope.contacts = [
        {name: 'GHI'},
        {name: 'DEF'},
        {name: 'ABC'},
        {name: 'JKL'}
    ];
}

查看

<div ng-controller="MyCtrl">
    <div><input type="text" ng-model="nameFilter" placeholder="Search..." /></div>
    <p ng-repeat="contact in contacts track by $index | filter: nameFilter | orderBy: name">{{ contact.name }}</p>
</div>

我不知道为什么订单不起作用以及过滤器无法正常工作的原因。

I don't know why the order is not working and why the filter is not working.

在另一个问题上,我读到了一些无法过滤或订购对象的内容。但我有一系列上面的对象。此外,它应该工作!?

At another question, I've read about something that objects can't be filtered or ordered. But I have an array of the objects above. Also, it should work!?

有什么问题?

推荐答案

要使用过滤器跟踪,必须在过滤器后添加跟踪表达式。

To use tracking with filters, the track by expression has to be added after the filter.

<p ng-repeat="contact in contacts | orderBy: 'name' | filter: nameFilter  track by $index">{{ contact.name }}</p>

这是工作 小提琴

这篇关于ng-repeat with track by和filter and orderBy not working的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆