Created
October 16, 2014 13:04
-
-
Save alperg/032ccd1f6861760ab2c2 to your computer and use it in GitHub Desktop.
ExtJS 5 store in viewmodel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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