Javascript 在ui select-Angularjs中获取所选选项的索引
我将Javascript 在ui select-Angularjs中获取所选选项的索引,javascript,angularjs,ui-select,Javascript,Angularjs,Ui Select,我将angularjs与ui选择一起使用() 我有以下代码: <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}}&l
angularjs
与ui选择一起使用()
我有以下代码:
<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>
{{$select.selected.name}
{{item.name}
在sourceChanged
函数中,我想知道所选项目的索引。。现在我只有值(scope.sender
)…
我可以在places
数组中搜索值,但这对我来说不够好,因为可能会有多个项目具有相同的值
有什么想法吗
谢谢:)您的重复表达错误
<ui-select-choices data-id="$index" repeat="item.name as item in places | filter:$select.search">
{{item.name}}
</ui-select-choices>
{{item.name}
您正在告诉ui选择、迭代trought places并在模型中绑定item.name,将其更改为
<ui-select-choices data-id="$index" repeat="item in places | filter:$select.search">
{{item.name}}
</ui-select-choices>
{{item.name}
它将完整的item对象绑定到ngModel,这样您就可以从places数组中获得原始项。如果您想要索引,您必须调用$scope.places.indexOf($scope.sender)
,它将返回原始数组中的索引