Sencha Touch: load store for List using Rest Proxy

99封情书 提交于 2019-12-25 11:26:02

问题


I'm new to sencha so I'm sure I'm just missing something simple here. I have a rest service and I need to be able to load my store for my list view.

Here's my model with the proxy:

Ext.define('UserModel', {
extend: 'Ext.data.Model',

config: {
    fields: [
        { name: 'UserId', type: 'int' },
        { name: 'FullName', type: 'string' }
    ],

    proxy: {
        type: 'rest',
        url: '/rest/user',
        reader: {
            type: 'json',
            root: 'user'
        }
    }
}
});

And this code works fine for a GET request. So I know that I'm able to talk with my rest service.

    var User = Ext.ModelMgr.getModel('UserModel');

    User.load(10058, {
        success: function (user) {
            console.log("Loaded user: " + user.get('UserId') + ", FullName: " + user.get('FullName'));
        }
    });

My problem is that I'm unable to load data into my list view when adding the proxy code to the store. How do I pass in a parameter to the rest service and load the store?

Ext.define('UserStore', {
extend: 'Ext.data.Store',

config: {
    model: 'UserModel',
    proxy: {
        type: 'rest',
        url: '/rest/user',
        reader: {
            type: 'json',
            root: 'user'
        },
        autoLoad: true
    },
    sorters: 'FullName',
    grouper: function(record) {
        return record.get('FullName')[0];       
    }
}

});

And here's my list view:

Ext.define('UserView', {
extend: 'Ext.List',
xtype: 'userView',

config: {
    scrollable: 'vertical',
    loadingText: "Loading your social connections . . .",
    indexBar: true,
    singleSelect: true,
    grouped: true,
    cls: 'customGroupListHeader',
    itemTpl: '{FullName}',
    store: 'UserStore',
    onItemDisclosure: true
}
});

回答1:


Haha! I knew it was something simple. The "autoLoad: true" in the store's proxy needs to be outside of the proxy's brackets.

Ext.define('UserStore', {
extend: 'Ext.data.Store',

   config: {
      model: 'UserModel',
      autoLoad: true,


来源:https://stackoverflow.com/questions/13887794/sencha-touch-load-store-for-list-using-rest-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!