简体   繁体   中英

Angular UI Select, Unique values pre-selected array

Lets say I have want to edit an existing entity that has an array of values that are also part of the selectable values. eg

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"}
]

My ui-select directive would be something like:

<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>

However the ui-select-choices option list cant seem to remove the duplicates, even though I have used track by language.id .

Any idea how to do this correctly?

It works for me in this way

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM