How get extjs-6 sotre's data in mvvm architecture?

882 Views Asked by At

I'm developing an Extjs 6 application using MVVM architecture. I have a model in MyApp/model folder as follow:

Ext.define('MyApp.model.User', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name',  type: 'string'},
        {name: 'age',   type: 'int'}
    ]
});

And my store in MyApp/store folder is as follow:

Ext.define('MyApp.store.User', {
    extend: 'Ext.data.Store',
    model: 'MyApp.model.User',
    data : [
     {firstName: 'Seth',    age: 34},
     {firstName: 'Scott', age: 72},
     {firstName: 'Gary', age: 19},
     {firstName: 'Capybara', age: 208}
    ]
});

And the in Application.js in /MyApp folder add the store as follow:

stores: [
    'User'
]

now I get store in my application as follow:

app = MyApp.getApplication();
users = app.getStore('User');

How can I get store's data? users.getData()? When I user users.getData() it returns [undefined x 4]. Where is the problem? Is it work correctly?

1

There are 1 best solutions below

0
AudioBubble On BEST ANSWER

you are using it correctly. You have to use users.getData().items as follow:

app = MyApp.getApplication(); users = app.getStore('User'); users.getData().items;