-
29 Sep 2009 9:42 AM #1
help with loading JSon to textfield
help with loading JSon to textfield
im trying to load some data from JSON file into a textfield as soon as its rendered (load it once the page is loaded).
im fairly new to extjs and so far i've tried something along the lines of:
where emailStore is the store with the fields to be loaded. and cc is the field to be loaded.Code:emailStore.on('load', function(textfield, record, index) { document.getElementById('cc').value = emailStore.getById('cc'); });
and also tried:
where cc is the id of the textfield.Code:cc.on('load', function(combo, record, index) { document.getElementById('cc').value = record.get('cc'); });
thanks,
NR
-
29 Sep 2009 11:02 AM #2
First off, a store's 'load' event handler always gets passed the store instance itself as the first parameter. So assigning the handler should look like:
The second parameter is an array of all loaded records. If you know you have only one record, you could doCode:emailStore.on('load', function(store, records, options) { ... });
A store's getById method retrieves a whole record, to assign a value, you need to access an individual entry in the record. Make sure to read the API docs and have a look at the various examples on this page, as well as browse the very good tutorials in the Learning Center at the ExtJS page.Code:if( records.length > 0 ) { document.getElementById('cc').value = records[0].get('cc'); }
Finally, if your textfield is an Ext.form.TextField, you need to use Ext.getCmp and setValue instead of assigning to document.getElementById(...).value
Code:Ext.getCmp('cc').setValue(records[0].get('cc'));


Reply With Quote