gpt4 book ai didi

javascript - ComboBox.store.loadData 无法加载单项数组

转载 作者:行者123 更新时间:2023-11-29 15:50:00 25 4
gpt4 key购买 nike

我正在使用 ExtJS 3.4。我有一个包含组合框数据的结构,如下所示:

var a = [[1,"text1"],[2,"text2"]]

我是这样加载的:

ComboBox.store.loadData(a);

但是当我在数组中只有一项时

var a = [[1,"text1"]]

然后它根本不会加载。我读过:

an Array : Arrays will be converted to a Ext.data.ArrayStore internally, automatically generating field names to work with all data components. 1-dimensional array : (e.g., ['Foo','Bar']) A 1-dimensional array will automatically be expanded (each array item will be used for both the combo valueField and displayField) 2-dimensional array : (e.g., [['f','Foo'],['b','Bar']]) For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo valueField, while the value at index 1 is assumed to be the combo displayField.

但这并没有解释我如何加载一个包含一个元素的数组。或者无论如何,它不应该是一个数组,关键是只加载一个项目。我试过加载这个:代码:

[{id:1,text:"text1"}]
[[{id:1,text:"text1"}]]
{id:1,text:"text1"}

甚至创建自定义 ArrayStore:

Code:
var store = new Ext.data.ArrayStore({
autoDestroy: true,
storeId: 'Store1',
idProperty:"id",
fields: ["id","text"]);
ComboBox.store = store;
ComobBox.store.loadData([{id:1,text:"text1"}]);

但是一切都加载不正确。组合框为空,或者它显示 id 而不是文本。

我可以看到,如果我懒惰地初始化组合:代码:

{"xtype":"combo","width":250,"fieldLabel":"my combo","value":31029,"forceSelection":true,"hiddenName":"ComboHiddenName","minChars":1,"triggerAction":"all","store":[[31029,"gdfs"]]}

然后包含一项的数组将加载成功。我应该在 ComboBox.store 的哪些属性中正确配置它们,以便使用 loadData 方法正确加载单项数组?

最佳答案

ComboBox.store.loadData(var a); 不适用于任何数据。它会引发异常 Unexpected token var。相反,应该使用不带 var

ComboBox.store.loadData(a);

关于javascript - ComboBox.store.loadData 无法加载单项数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6718393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com