2016-02-19 4 views
0

Я использую директиву ngTagsInput с автозаполнением. Все работает нормально, если у меня нет двух тегов с одним и тем же свойством «tag_token».ngRepeat: dupes - Дубликаты в ретрансляторе не разрешены

Это мой ответ, что я получаю:

{ 
"id": "100", 
"create_date": "2016-02-01T18:33:39Z", 
"tag_token": "Tag 1", 
"parent_id": "1", 
"parent_type": "FILE" 
}, 
{ 
"id": "101", 
"create_date": "2016-02-01T18:33:39Z", 
"tag_token": "Tag 2", 
"parent_id": "2", 
"parent_type": "FILE" 
}, 
{ 
"id": "102", 
"create_date_tdt": "2016-02-01T18:33:39Z", 
"tag_token": "Tag 2", 
"parent_id": "3", 
"parent_type": "FILE" 
} 

VIEW

    <tags-input    
        ng-model="searchQuery" 
        display-property="tag_token" 
        key-property="tag_token" 
        on-tag-adding="checkTag($tag)" 
        on-tag-removed="onTagRemoved($tag)" 
        replace-spaces-with-dashes="false" 
        add-from-autocomplete-only="true" 
       > 
       <auto-complete min-length="1" max-results-to-show="10" source="typeahead($query)"></auto-complete> 
       </tags-input> 

Я получаю эту ошибку:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in suggestionList.items track by track(item), Duplicate key: Tag 2, Duplicate value: {"tag_token":"Tag 2"} 
http://errors.angularjs...... 
    at angular.js:68 
    at ngRepeatAction (angular.js:27518) 
    at Object.$watchCollectionAction [as fn] (angular.js:15761) 
    at Scope.$digest (angular.js:15896) 
    at Scope.$apply (angular.js:16160) 
    at done (angular.js:10589) 
    at completeRequest (angular.js:10787) 
    at XMLHttpRequest.requestLoaded (angular.js:10728) 

ответ

0

На тегах вход попробовать key-property="tag_token track by $index"

+0

Ну я попробовать это тоже ... но не успех опять же error .... Duplicate value: {"tag_token track by $ index": "Tag 2"} – Bukic

0

Использование key-property="id". Вот demo

например.

<tags-input    
     ng-model="searchQuery" 
     display-property="tag_token" 
     key-property="id" 
     replace-spaces-with-dashes="false" 
     ... 
     ... 
0

использование key-property="id" display-property="tag_token"

Синтаксис: если у вас есть этот тип JSON

[ 
    { 
    name:"Rohit", 
    id:"2" 
    }, 
    { 
    name:"Virat", 
    id:"2" 
    } 
] 

затем использовать key-property="id" display-property="name"

Смежные вопросы