1

我是 sencha touch 应用程序开发的新手。我正在尝试将一些数据从远程服务器加载到列表中。我创建了一个商店,如下所示

Ext.regStore('customers',{

model : 'customer',
sorters : 'firstName',
storeId : 'customers',
data : [{
    id : 100,
    firstName : 'aaa'
}, {
    id : 101,
    firstName : 'sss'
}, {
    id : 102,
    firstName : 'rrrr'
}]

});

现在我需要修改这个商店以从外部服务器检索数据。Follwoing 是我现在正在使用的代码

var customers = new Ext.data.JsonStore({
        model : 'customer',

           proxy : {
            type : 'ajax',
            url:'http:sample.com',

            reader : {
                type : 'json',
                root : '',
            },                              
        },

        listeners : {

            datachanged : function() {

                customers.each(function(r) {
                    console.log('data in record is:'+ r.get('name'));
                });
            }
        },
    });

现在我的疑问是,如何像初始代码一样注册这个 JSON 存储以从另一个视图控制器文件访问存储。

提前致谢

4

1 回答 1

0

您可以使用该属性:

storeId = "NameOfStoryID"

填写商店后,您可以稍后在代码中使用此 storeId 访问商店(获取数据、更新数据等)。

例子:

    var schouwLijstStore = new Ext.data.Store({

        model: "schouwLijst",
        storeId: "myStore",
        proxy: {
            type: 'ajax',
            url: 'php/json.php?t=list',
            reader: {
                type: 'json',
                root: 'list'
            },   
        },    
        autoLoad: true,
        listeners: {
            load: function() {

                               // Do things on load (sync to offline store for example)

            }

        }

    });

现在要稍后在代码中访问您的商店,您可以使用您的 storeID。例如加载它:

// 加载 myStore.load();

// 添加项目 myStore.add({ id: * , value: * });

等等

于 2011-11-21T17:49:43.307 回答