Reputation: 83
Im currently having an issue regarding stores declared in ViewModel, using Extjs5's MVVM feature.
Simple Use case:
ViewModel:
Ext.define('App.view.view1.View1Model', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.view1',`
data: {
},
stores:{
Company:{
model: 'UM.model.CompanyData',
type: 'CompanyData', //Store name
autoLoad: true
}
}
}];
While code below is my viewController:
ViewController:
Ext.define('App.view.view1.View1Controller', {
extend: 'Ext.app.ViewController',
alias: 'controller.view1',
onloadnewdata: function(event, item,store){
var vm= this.getViewModel();
var store=vm.getStore('Company');
console.log(store);
}
});
On firing some event with "onloadnewdata" function based on the console store is null.
All I need to do is get the store declared on the ViewModel. Please help me which part is wrong or is this a bug? Appreciate if you share some ideas or other approach. Thanks.
Upvotes: 2
Views: 6564
Reputation: 195
I think you need to modify the code something like below. In order to get the reference to the ViewModel first you need to get the reference to View.
Ext.define('App.view.view1.View1Controller', {
extend: 'Ext.app.ViewController',
alias: 'controller.view1',
onloadnewdata: function(event, item,store){
var store = this.getView().getViewModel().getStore('Company');
console.log(store);
}
});
You can refer this sencha fiddle https://fiddle.sencha.com/#fiddle/fpb. Just check this following controller TestApp.view.grid.GenericGridController . Hope it helps!
Upvotes: 4