-
17 Jun 2011 6:37 AM #1
dynamic fill select field
dynamic fill select field
hello I'm new in Sencha Touch
I'd like to fill a select field with selectfield.setoptions()
I got the data from a JSONP Request
If I put the text from the var directly into the selectfield.setoptions(text); it's working. but I need it dynamicly
Code:Ext.util.JSONP.request({ url: 'http://localhost:8080/BaReq/', //URL callbackKey: 'callback', params: { action: 'getstatements', //Parameter for URL callback: 'true', //also Parameter for URL format: 'json' }, callback: function (result) { var result1 = result.BaReq.categories; //ok! // alert(result1[1].name); //alert(result1.length); var optionArray = '['; for (var i=0; i < result1.length; i++){ optionArray = optionArray + '{text: \''+result1[i].name+'\', value: \''+(i+1)+'\'},'; } optionArray = optionArray.substr(0,optionArray.length-1); optionArray = optionArray +']'; alert(optionArray); //optionArray is correct, if i put the input in the //setOptions([{text: 't1', value: '1'}, {text: 't2', value '2'}]) method, it's working //on the next line is the error... Uncaught TypeError: Cannot read property 'id' of undefined Ext.getCmp('scannedObject1').setOptions(this.optionArray); Ext.getCmp('scannedObject1').setValue('1'); Ext.getCmp('formresult').doLayout(); } });
Thanks for any help
-
19 Jun 2011 11:25 PM #2
hello
i got exactly the same problem. how i can i fill a selectfield dynamically?
thanks!
greetings
-
30 Jun 2011 2:05 AM #3
I've solved it with a store

-
20 Jul 2011 12:40 AM #4
-
3 Aug 2011 11:23 PM #5
Sorry for the late reply, I was in holiday.
I work with a store where all entry are in it. But they have an extra field, where i can put the selection criterion..
For example male/female
This listeners is the trigger for changing the variables of the select field:
Code:listeners: { change: function(){ //This is the dynamic selectfield var detailedSelect = MyApp.FormPanel.items.get('detailedRequest'); //I remove the old Filter detailedSelect.store.clearFilter(); // remove the previous filter //And i set the new Filter with the active value of another select field detailedSelect.store.filter('cat', Ext.getCmp('scannedObject').getValue()); //Here I set a value in the dynamic selectfield, which should be shown.. it's the first entry of the new filter var newSelection = detailedSelect.store.getAt(0); // if not undefined we can set the value to the first record's if(newSelection){ detailedSelect.setValue(newSelection.data.value); } else { detailedSelect.setValue(''); } } }
If the description isn't helpful enough i'll try to explain it better..
Greez
-
4 Aug 2011 12:01 AM #6


Reply With Quote