简体   繁体   中英

How to access a value fetched from a JsonStore with ExtJS?

In the following JS code, I am trying to read json data from url:

// Create JsonStore
var storeED = new Ext.data.JsonStore({                    
            url: './wfServlet?workd=' + workd
                + '&type=detail' + '&status=' + status +'&userName='+userName,
            root: 'root',
            fields: [{name:'ERROR_DESC'}]
            });

then I want to get the value from the field ERROR_DESC .

Ext.getCmp('errorMessage').setValue(storeED.ERROR_DESC);// want  to read value

The code just above doesn't work for me.
What am I missing ?

Stores don't have values. Stores are caches of Ext.data.Model instances, which are what hold values which are mapped to the fields defined for the Model which is applied to the Store.

To accomplish what you're trying to do, you'll need to access the instance of the Model inside your store which contains the record data you desire, such as storeEd.getAt(0) , assuming you only have one model instance in your store's cache.

If this is the only field AND you only expect one instance to live within this store, it might be better to not even bother with a store at all. You could either add a proxy to the Model itself, or just use the value returned from a regular Ext.Ajax.request . If you don't plan on using this value beyond this particular usage, a store is probably unnecessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM