首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ui-select - Angularjs中获取选择索引

在ui-select - Angularjs中获取选择索引
EN

Stack Overflow用户
提问于 2015-06-27 10:45:21
回答 1查看 4.7K关注 0票数 1

我使用angularjsui-select (https://github.com/angular-ui/ui-select/)

我有这样的代码:

代码语言:javascript
复制
<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数组中搜索值,但是它对我来说还不够好,因为有可能会有几个具有相同值的项。

有什么想法吗?

谢谢:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-27 10:51:00

你错了重复一遍。

代码语言:javascript
复制
<ui-select-choices data-id="$index" repeat="item.name as item in places | filter:$select.search">
        {{item.name}}
    </ui-select-choices>

您正在告诉用户界面-选择、迭代已形成的位置并将item.name绑定到模型中,将其更改为

代码语言:javascript
复制
<ui-select-choices data-id="$index" repeat="item in places | filter:$select.search">
        {{item.name}}
    </ui-select-choices>

它将将完整的item对象绑定到ngModel,因此您可以从多个位置获得原始项。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31087858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档