ComboBox.store.loadData 无法加载单项数组
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ComboBox.store.loadData(var a);
不适用于任何数据。它会引发异常Unexpected token var
。相反,应该使用不带var
的ComboBox.store.loadData(a);
ComboBox.store.loadData(var a);
would not work for any data. It would raise exceptionUnexpected token var
. Instead one should useComboBox.store.loadData(a);
withoutvar