0

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?

Guilherme Lopes
  • 4,688
  • 1
  • 19
  • 42
Morteza Malvandi
  • 1,656
  • 7
  • 30
  • 73
  • The question is incorrect. MVVM - Model View ViewModel. You don't have a ViewModel. You should define a store in a ViewModel and can get a data over .getViewModel().get().getData(). If you just want to iterate over all records you can use method "each" of the store instead of getting data. In any case your question is nothing to do with MVVM. – yorlin Oct 03 '15 at 18:00

1 Answers1

1

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

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

Morteza Malvandi
  • 1,656
  • 7
  • 30
  • 73