开发者

ComboBox.store.loadData can't load single-item array

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

开发者_Python百科
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?


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


ComboBox.valueField = "id";
ComboBox.displayField = "text";
ComboBox.store = new Ext.data.ArrayStore({autoDestroy: true, fields: ["id", "text"]});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜