5

假设我想要编辑一个现有实体,该实体具有一组值,这些值也是可选值的一部分。例如

var preSelectedLanguages = [
    {id: 2, iso: "de"},
    {id: 3, iso: "fr"}
]

var languages = [
    {id: 1, iso: "en"},
    {id: 2, iso: "de"},
    {id: 3, iso: "fr"},
    {id: 4, iso: "it"},
    {id: 5, iso: "us"}
]

我的 ui-select 指令将类似于:

<ui-select multiple ng-model="preSelectedLanguages">
    <ui-select-match placeholder="Select language...">
        {{$item.iso}}
    </ui-select-match>
    <ui-select-choices repeat="l in languages track by language.id">
        {{language.iso}}
    </ui-select-choices>
</ui-select>

然而,ui-select-choices选项列表似乎无法删除重复项,即使我使用过track by language.id.

知道如何正确执行此操作吗?

4

1 回答 1

2

它以这种方式对我有用

<ui-select multiple ng-model="preSelectedLanguages">
    <ui-select-match placeholder="Select language...">
        {{$item.iso}}
    </ui-select-match>
    <ui-select-choices repeat="l in languages track by l.id">
        {{l.iso}}
    </ui-select-choices>
</ui-select>
于 2015-09-27T16:22:03.757 回答