1

I want to retrieve all datas from store for doing some validations in sencha extjs6. I have a model, a store, and one json file. But I don't know how to get the store value from json. For example, store the value from store to an variable or array for my further validation. Please kindly help me on this since I am new to sencha extjs. Here is my codes:

Model

Ext.define('MyApp.model.MobilePrefix', {

extend: 'Ext.data.Model',

config: {

    fields: [
        {name: 'id', type: 'int'},
        {name: 'prefix', type: 'string'},
        {name: 'length', type: 'int'}
    ]   
}
});

Store

Ext.define('MyApp.store.MobilePrefix', {

extend: 'Ext.data.Store',

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

config: {
    model: 'MyApp.model.MobilePrefix',

    proxy: {
        type: 'ajax',
         url: 'resources/data/MobilePrefix.json',


        reader: {
            type: 'json',
            rootProperty: 'MobilePrefix'
        }
    },

    autoLoad: true
}

});

Json MobilePrefix.json

{
"MobilePrefix": [
    {"id": 1, "prefix":"012", "length":6 },
    {"id": 2, "prefix":"015", "length":6 },
    {"id": 3, "prefix":"097", "length":7 }
   ]
}

Thanks in advance.

Phon Soyang
  • 1,303
  • 2
  • 9
  • 17

1 Answers1

0

Use listeners in you Store file.

Ext.define('MyApp.store.MobilePrefix', {
extend: 'Ext.data.Store',
requires: ['MyApp.model.MobilePrefix'],
autoLoad: true,
config: {
    model: 'MyApp.model.MobilePrefix',
    proxy: {
        type: 'ajax',
        url: 'resources/data/MobilePrefix.json',


        reader: {
            type: 'json',
            rootProperty: 'MobilePrefix'
        }
    },
    listeners: {
        load: function(store) {
            console.log(store.data);
        }

    }
}
});
Ajay Thakur
  • 1,066
  • 7
  • 23