开发者

combobox and Value collided

开发者 https://www.devze.com 2023-03-08 05:42 出处:网络
I am using the dojo combobox together with json. I have the error :Items within the list开发者_如何学C have identifier: [id].Value collided: [48]

I am using the dojo combobox together with json. I have the error : Items within the list开发者_如何学C have identifier: [id]. Value collided: [48] If I look at my raw json, I only have two objects which id is 41 and 48 but when I look at my ItemFileReadStore i have four objects, one of them is the object with id=41 and the three others are the same duplicated objects with id=48

the method is use for the ItemFileReadStore is :

var store = new dojo.data.ItemFileReadStore( { data: {
                  identifier: "id",
                  items: data
                }});

                console.log(store);

                var filteringSelect = new dijit.form.ComboBox({
                    store: store,
                    searchAttr: "nafn"
                },
                "nafn");

What could be the source of the problem ?


i observed certain errors in your code.

1)dojo.data.ItemFileReadStore expects data to be in certain format you are missing that format. the format will be something like this.

var storeData = {identifier : 'uniqueIdOfEachItem', label : 'displayName', items : [
  {uniqueIdOfEachItem:1,displayName:'somename'},
  {uniqueIdOfEachItem:2,displayName:'somename2'}
]}
var store = new dojo.data.ItemFileReadStore({data: storeData })
var filteringSelect = new dijit.form.ComboBox({
                store: store ,
                searchAttr: "displayName"
            },
            "id_of_element_in_html_where_your_combo_will_sit");

2)searchAttr in ComboBox should be one of the props of the store item (here uniqueIdOfEachItem or displayName).

3) Please make sure that the identifier(here uniqueIdOfEachItem) for each item in the store is unique, if its not unique then combo box will not work, throwing some error similar to what you have mentioned.


I indeed corrected my code. I also found out that the problem was that my entity has two self referencing fields and therefore the same id could be found many times.

In my case a personn had two parents, mother and father that were also personn with their id.

It looked something like :

[{id:'1',name:'john',father:{id:'2',name:'gils'},mother:{id:'3',name:'loa'}}]
[{id:'1',name:'nora',father:{id:'2',name:'gils'},mother:{id:'3',name:'loa'}}]

I have a conflict because id[2] collided.

I had to remove the two field mother and father and that solved the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消