我将angularjs
与ui-select
(https://github.com/angular-ui/ui-select/)
我有这段代码:
<ui-select tagging="addTagging" tagging-tokens="ENTER" ng-change="sourceChanged()" ng-model="sender" theme="bootstrap" sortable="true" ng-disabled="disabled">
<ui-select-match>{{$select.selected.name}}</ui-select-match>
<ui-select-choices data-id="$index" repeat="item.name as item in places | filter:$select.search">
{{item.name}}
</ui-select-choices>
</ui-select>
在sourceChanged
函数内部我想知道所选项目的索引..现在我只有值(scope.sender
)..
我可以搜索places
数组中的值,但这对我来说不够好,因为有可能会有几个具有相同值的项目......
有什么想法吗?
谢谢:)
答案 0 :(得分:2)
你错了重复expr。
<ui-select-choices data-id="$index" repeat="item.name as item in places | filter:$select.search">
{{item.name}}
</ui-select-choices>
你正在告诉ui-select,迭代trought的地方并将item.name绑定到模型中,将其更改为
<ui-select-choices data-id="$index" repeat="item in places | filter:$select.search">
{{item.name}}
</ui-select-choices>
它会将完整的项目对象绑定到ngModel,因此您可以从场所数组中获得原始项目。