我有一个对象数组(~650)的格式
[1: {firstName: "Hello",
lastName: "World",
shortName: "h.world",
...some other items
},
2: {firstName: "John",
lastName: "Doe",
shortName: "j.doe",
...some other items
}]
我需要根据文本输入过滤列表
firstName+ " "+lastName
。所以搜索
He
或
Hello W
将返回
Hello World
、和搜索
Hellow
不会退还(情况无关紧要)。过滤阵列的最佳方法是什么?我看过Angulars过滤方法,但我还没有弄清楚该怎么做。
编辑我所拥有的
<div ng-controller="NotesCtrl">
<p>Search for a user to see there sessions and notes</p>
<input type="text" id="user" ng-model="search.firstName" />
{literal}
<ul>
<li ng-repeat="u in users | filter:search">{{u.activeDirectoryName}}</li>
</ul>
{/literal}
</div>
从我所读到的内容来看,这应该是可行的,但列表没有过滤。我需要在控制器中执行任何操作才能使其正常工作吗?
答:事实证明,即使在PHP中,我的数据是一个数组,但在Javascript中,它是一个对象,稍微改变了一下,所以它以数组的形式出现,现在似乎可以工作了。