Skip to content

Instantly share code, notes, and snippets.

@alperg
Created October 16, 2014 13:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alperg/032ccd1f6861760ab2c2 to your computer and use it in GitHub Desktop.
Save alperg/032ccd1f6861760ab2c2 to your computer and use it in GitHub Desktop.
ExtJS 5 store in viewmodel
In file MyApp/store/Menu.js
Ext.define('MyApp.store.Menu', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.menu.Root'
],
model: 'MyApp.model.menu.Root',
proxy: {
type: 'ajax',
url: '/rest/menu',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});
In file MyApp/view/menu/MenuModel.js
Ext.define('MyApp.view.menu.MenuModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.menu',
requires: [
'MyApp.store.Menu',
],
constructor: function() {
this.callParent(arguments);
this.setStores({menu:{
source: Ext.create('MyApp.store.Menu')
}
});
}
});
In my ViewController :
...
onPanelRender: function() {
this.getView().getViewModel().getStore('menu').[[[getSource()]]].load(function(records, op, success) {
...
});
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment