View Full Version : help with loading JSon to textfield

29 Sep 2009, 9:42 AM
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:

emailStore.on('load', function(textfield, record, index) {
document.getElementById('cc').value = emailStore.getById('cc');
where emailStore is the store with the fields to be loaded. and cc is the field to be loaded.

and also tried:

cc.on('load', function(combo, record, index) {
document.getElementById('cc').value = record.get('cc');
where cc is the id of the textfield.


29 Sep 2009, 11:02 AM
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:

emailStore.on('load', function(store, records, options) {

The second parameter is an array of all loaded records. If you know you have only one record, you could do

if( records.length > 0 ) {
document.getElementById('cc').value = records[0].get('cc');

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.

Finally, if your textfield is an Ext.form.TextField, you need to use Ext.getCmp and setValue instead of assigning to document.getElementById(...).value