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

发布于 2024-11-25 03:50:17 字数 1433 浏览 5 评论 0原文

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

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

我像这样加载它:

ComboBox.store.loadData(a);

但是当我数组中只有 1 个项目时

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

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

数组:数组将被转换为 Ext.data.ArrayStore 在内部自动生成字段名称以处理所有数据 成分。一维数组:(例如,['Foo','Bar'])A 一维数组会自动扩展(每个数组项 将用于组合 valueField 和 displayField) 二维数组:(例如,[['f','Foo'],['b','Bar']])对于 多维数组,每一项的索引 0 中的值将是 假定为组合 valueField,而索引 1 处的值是 假定为组合显示字段。

但这并不能解释如何加载包含一个元素的数组。或者无论如何,不​​需要一个数组,重点是只加载一个项目。我试过加载这个: 代码:

[{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 方法正确加载单项数组?

I am using ExtJS 3.4 .
I have a structure with data for combobox like this:

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

I load it like this:

ComboBox.store.loadData(a);

But when I have only 1 item in the array

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

then it doesn't load at all. I've read that:

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.

But that doesn't explain how do I load an array with one element. Or whatever, it shouldn't be necessary an array, the point is to load only one item. I've tried loading this:
Code:

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

Even creating a custom 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"}]);

But everything loads incorrectly . Either the combobox is empty, or it displays id instead of text.

I can see that if I lazily init the combo:
Code:

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

then the array with one item will load successfully. At which properties of ComboBox.store should I look to configure them properly for a single-item array to be loaded correctly using loadData method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨与橙与城 2024-12-02 03:50:17

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

ComboBox.store.loadData(var a); would not work for any data. It would raise exception Unexpected token var. Instead one should use ComboBox.store.loadData(a); without var

摘星┃星的人 2024-12-02 03:50:17
ComboBox.valueField = "id";
ComboBox.displayField = "text";
ComboBox.store = new Ext.data.ArrayStore({autoDestroy: true, fields: ["id", "text"]});
ComboBox.valueField = "id";
ComboBox.displayField = "text";
ComboBox.store = new Ext.data.ArrayStore({autoDestroy: true, fields: ["id", "text"]});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文