Javascript 过滤多个特定值上的ng重复

Javascript 过滤多个特定值上的ng重复,javascript,angularjs,Javascript,Angularjs,我试图用数据的两列过滤ng重复 数据 名称(字符串) 地址=[{city(string)}](数组) HTML <input type="text" class="search-query" ng-model="search.attributes.name" /> <select ui-select2 id="select2" data-placeholder="Type" ng-model="search.attributes.address.0.city" class=

我试图用数据的两列过滤ng重复

数据

  • 名称(字符串)
  • 地址=[{city(string)}](数组)
HTML

<input type="text" class="search-query" ng-model="search.attributes.name" />
<select ui-select2 id="select2" data-placeholder="Type" ng-model="search.attributes.address.0.city" class="form-control">
        <option value=""></option>
        <option ng-repeat="type in types" value="{{type}}">{{type}}</option>
</select>

<tr ng-repeat="resource in resources | filter:search | limitTo: 10">

{{type}}

出于某种原因,在本例中,没有任何数据显示出来。虽然当我完全删除
选择
框时,它会全部填充,但当我在搜索框中键入内容时,什么也不会显示(好像过滤器过滤掉了所有内容)。

似乎search.attributes.name不是作为
''
启动的,而是作为
未定义的
启动的。因此,过滤器没有默认为允许任何内容,而是默认为只允许未定义的内容,即无

因此,答案是将此添加到我的控制器:

$scope.search = {};
$scope.attributes.name = '';
$scope.attributes.address.0.city = '';

你能输出
search
对象吗,它看起来怎么样?我建议你使用
而不是手动执行
ng repeat
。它不仅使您的代码更干净,而且可以自动完成许多您尝试执行的操作。你可以看到这方面的文档。