Get a particular value from Store in Sencha Touch?

2019-08-30 02:31发布

问题:

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.