组合框和值相冲突 [英] combobox and Value collided

查看:97
本文介绍了组合框和值相冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和json一起使用dojo组合框。
我有错误:列表中的项目具有标识符:[id]。价值相撞:[48]
如果我看看我的原始json,我只有两个对象,id是41和48
,但是当我看到我的ItemFileReadStore我有四个对象,其中之一是对象的id = 41,另外三个是id = 48相同的重复对象



该方法用于ItemFileReadStore是:

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

可能是问题的根源是什么?

解决方案

我观察到你的代码中的某些错误。



1)dojo.data.ItemFileReadStore期望数据具有某种格式你缺少这种格式。
格式将是这样的。

  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)ComboBox中的searchAttr应该是商店项目的一个道具(这里是uniqueIdOfEachItem或displayName)



3)请确保商店中每个商品的标识符(这里uniqueIdOfEachItem)是唯一的,如果它不是唯一的,那么组合框将不起作用,抛出一些错误类似于您提到的错误。


I am using the dojo combobox together with json. I have the error : Items within the list 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.

这篇关于组合框和值相冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆