Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value from Ext.data.Store ?

Tags:

extjs

this is my code

var store = {
    user_store: new Ext.data.Store({
        autoLoad: false,
        proxy: new Ext.data.HttpProxy({
            url: 'a/b/c',
        }),
        remoteSort: true,
        baseParams: {

        },
        reader: new Ext.data.JsonReader({
            totalProperty: 'total',
            root: 'root',
            fields: ['roles']
        })
    })
};
store.user_store.load();​

this is my json

{"roles":"2"}

I wnat to ask. How do I get the roles's value is "2".

(PS:Sorry,my English is not very well.)

like image 549
陳同學 Avatar asked Nov 15 '12 11:11

陳同學


People also ask

What is store in Ext JS?

Stores load data via a Ext. data. proxy. Proxy, and also provide functions for sorting, filtering and querying the Ext. data.

What is listeners in Ext JS?

Built-in Events Using ListenersExt JS provides listener property for writing events and custom events in Ext JS files. We will add the listener in the previous program itself by adding a listen property to the panel. This way we can also write multiple events in listeners property.

What is Proxy in Ext JS?

Proxies operate on the principle that all operations performed are either Create, Read, Update or Delete. These four operations are mapped to the methods create, read, update and erase respectively. Each Proxy subclass implements these functions. The CRUD methods each expect an Ext.


1 Answers

If there is only one item in the response, you can add a callback function to the load method:

var store = {
    user_store: new Ext.data.Store({
        autoLoad: false,
        proxy: new Ext.data.HttpProxy({
            url: 'a/b/c',
        }),
        remoteSort: true,
        baseParams: {

        },
        reader: new Ext.data.JsonReader({
            totalProperty: 'total',
            root: 'root',
            fields: ['roles']
        })
    })
};
store.user_store.load(function(){
    this.getAt(0).get('roles')
});​

If the the response consist of several items like: [{"roles":"2"},{"roles":"1"}] you can iterate the store to retrieve all values.

store.user_store.load(function(){
    this.each(function(record){
       var roles = record.get('roles');
       // Do stuff with value
    });
});​
like image 146
Carl Avatar answered Oct 18 '22 14:10

Carl