Plunkr:http ://plnkr.co/edit/VR4p6n8rbrGZZOCcCrIa?p=preview
我正在使用 angular-ui-select 插件。
我正在尝试根据城市、州和国家/地区过滤项目。
我用于绑定下拉列表的数据具有以下结构:
vm.people = [
{ name: 'Adam', email: 'adam@email.com', age: 12,
state: {state:"NY", country:{country:"US"}
}
},
{ name: 'Amalie', email: 'amalie@email.com', age: 12
, state: {state:"ca", country:{country:"US"}
}
},
{ name: 'Estefanía', email: 'estefania@email.com', age: 21
, state: {state:"al", country:{country:"US"}
}
},
{ name: 'Adrian', email: 'adrian@email.com', age: 21
, state: {state:"po", country:{country:"US"}
}
},
{ name: 'Wladimir', email: 'wladimir@email.com', age: 30
, state: {state:"mn", country:{country:"US"}
}
},
{ name: 'Samantha', email: 'samantha@email.com', age: 30
, state: {state:"na", country:{country:"US"}
}
},
{ name: 'Nicole', email: 'nicole@email.com', age: 43
, state: {state:"NX", country:{country:"US"}
}
},
{ name: 'Natasha', email: 'natasha@email.com', age: 54
, state: {state:"NY", country:{country:"US"}
}
},
{ name: 'Michael', email: 'michael@email.com', age: 15
, state: {state:"NY", country:{country:"US"}
}
},
{ name: 'Nicolás', email: 'nicolas@email.com', age: 43
, state: {state:"NY", country:{country:"US"}
}
}
];
我将其绑定如下:
<ui-select ng-model="ctrl.person.selected" theme="bootstrap">
<ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="item in ctrl.people | propsFilter: {name: $select.search, state.state: $select.search,state.country.country: $select.search} ">
<div ng-bind-html="item.name | highlight: $select.search"></div>
<small ng-bind-html="item.email | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
我收到此错误:
错误:[$parse:syntax] 语法错误:令牌 '.' 是出乎意料的,在表达式 [ctrl.people | 的第 57 列期望 [:] propsFilter: {name: $select.search, state.state: $select.search,state.country.country: $select.search}] 从 [.state: $select.search,state.country.country: $select 。搜索}]。
编辑:我可以通过在整个 json 中 使用过滤器而不是propsfilter和搜索来解决这个错误。但我不想这样做,因为 json 中有很多列我什至没有向用户显示..