Sencha Touch: load store for List using Rest Proxy

2019-08-25 18:23发布

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条回答
We Are One
2楼-- · 2019-08-25 18:57

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,
查看更多
登录 后发表回答