3
votes

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?

2
Which version of ExtJs are you using?Zango
why would you want a store with one record?JamesHalsall
@Jaitsu how do load one item to a combobox otherwise, without using a store?Bogdan Verbenets
that's exactly my point, why would you ever have a combo box that only has one option?JamesHalsall

2 Answers

1
votes

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

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