Get a particular value from Store in Sencha Touch?

为君一笑 提交于 2019-12-12 04:38:46

问题


I've created a model with following structure:

Model Code:

Ext.define('MyApp.model.FavoriteScreen', {
extend: 'Ext.data.Model',

config: {
    fields: [
        {
            name: 'Name'
        },
        {
            name: 'ScreenId'
        }
    ]
}

});

And I've created a store with following structure:

Store code:

Ext.define('MyApp.store.FavoriteStore', {
extend: 'Ext.data.Store',

requires: [
    'MyApp.model.FavoriteScreen'
],

config: {
    autoLoad: true,
    model: 'MyApp.model.FavoriteScreen',
    storeId: 'FavStore',
    proxy: {
        type: 'ajax',
        api: {
            read: '/api/sample/FavoriteList'
        },
        headers: {
            'Content-Type': 'application/json; charset=UTF-8'
        },
        reader: {
            type: 'json',
            rootProperty: 'data'
        }
    }
}

});

Now I want to get particular record from this store but my store does not return any value. To get value from store I've written following line of code:

var myStore = Ext.getStore('FavStore');

myStore.load({
    scope: this,
    callback: function (records, operation, success) {
        if (success) {
            Ext.Msg.alert(myStore.getAt(0).getData());
        }
    }
});

The above code I've written on The above code I’ve written on nestedlistleafitemtap event.

Any help is appreciated!!


回答1:


First of all - don't use getData() - use get('name') for example.

Second - try to add logging before your loading call and inside your callback function. This way you can see whether you started loading and was it completed.



来源:https://stackoverflow.com/questions/16918331/get-a-particular-value-from-store-in-sencha-touch

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