过滤由 ng-repeat 创建的不同列表 (AngularJS)

Filter different lists created by ng-repeat (AngularJS)

我有两个选项卡,其中包含由 ng-repeat 创建的不同列表

当我过滤第二个标签时 - 一切正常,但第一个标签根本不起作用。

我现在这个问题是因为 <ul search-list=".letter" model="search.district"><input id="q" type="text" ng-model="search.district " />,但是 search.district 我需要第二个选项卡正确过滤。如果您要在 search 上更改 search.district - 过滤将在两个选项卡上工作,但在第二个选项卡上过滤将不正确(过滤器应该过滤地区,当我们单击 Z 时显示字母 z) 的所有城市。

所以,问题是,如何在我的代码中保留 search.district,以及如何使过滤器在两个选项卡中都正常工作?

这里正在工作DEMO

非常感谢!

startWith 函数中你假设 expected 是字符串,但对于第一个面板比较是一个对象,更改代码如下:

var e = angular.isString(expected) ? expected.toLowerCase() : expected.district.toLowerCase();

然后使用 e 变量作为 indexOf 参数。