如何从Ext.data.Store获取值? [英] How to get value from Ext.data.Store ?

查看:580
本文介绍了如何从Ext.data.Store获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

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();​

这是我的json

{"roles":"2"}

我不想问如何获得角色的价值是2。

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

(PS:对不起,我的英文不是很好。)

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

推荐答案

如果响应中只有一个项目,可以向加载方法添加回调函数:

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')
});​

如果响应由以下几个项目组成: [{roles:2},{roles 1}]
您可以迭代商店检索所有值。

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
    });
});​

这篇关于如何从Ext.data.Store获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆