假设我想要编辑一个现有实体,该实体具有一组值,这些值也是可选值的一部分。例如
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选择指令类似于:
<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
。
知道如何正确地做到这一点吗?
它以这种方式对我有效
<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>