我使用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数组中搜索值,但是它对我来说还不够好,因为有可能会有几个具有相同值的项。
有什么想法吗?
谢谢:)
发布于 2015-06-27 10:51:00
你错了重复一遍。
<ui-select-choices data-id="$index" repeat="item.name as item in places | filter:$select.search">
{{item.name}}
</ui-select-choices>您正在告诉用户界面-选择、迭代已形成的位置并将item.name绑定到模型中,将其更改为
<ui-select-choices data-id="$index" repeat="item in places | filter:$select.search">
{{item.name}}
</ui-select-choices>它将将完整的item对象绑定到ngModel,因此您可以从多个位置获得原始项。
https://stackoverflow.com/questions/31087858
复制相似问题