javascript - ngRepeat :dupes - Duplicates in a repeater are not allowed

标签 javascript html angularjs ng-tags-input

我正在使用带自动完成功能的 ngTagsInput 指令。如果我没有两个具有相同“tag_token”属性的标签,一切正常。

这是我得到的回复:

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

查看

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

最佳答案

使用 key-property="id"。这是 demo

例如

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

关于javascript - ngRepeat :dupes - Duplicates in a repeater are not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35516637/

相关文章:

javascript - 启动一个带有碎片页面的 Angular 项目

html - 在 URL 中传递用户名和密码不起作用

php - 如何将 mysql_num_rows 等函数更改为 mysqli?

java - 如何在java上重写url

angularjs - 部署生产 MEAN Stack 应用程序的指南

javascript - 使用 ASP .NET MVC 推出新版本的 JavaScript、CSS 和图形内容

javascript - 在生产中使用 "coffee"而不是 "node"命令

html - w3c 链接检查器中的损坏链接问题

jquery - 使用显示更少/更多选项截断多行 HTML 绑定(bind)

javascript - 如何在 vue.js 中选择 getter 中的最后一个元素