I'm used to ExtJs with MVC pattern, and I'm trying to implement MVVM pattern. I'm not able to bind a store to my view.
I have a main grid, and try to open a details grid when selecting a line.
detailsView = mainPanel.add({
xtype: 'rma-details',
viewModel: {data: {id: id}}
})
Ext.define('Mb.view.rma.Details', {
extend: 'Ext.grid.Panel',
alias: 'widget.rma-details',
requires: [
'Mb.view.rma.DetailsController',
'Mb.view.rma.DetailsModel'
],
controller: 'rma-details',
viewModel: {type: 'rma-details'},
bind: {
title: 'Retour n° {id}',
store: '{details}'
},
(...)
});
Ext.define('Mb.view.rma.DetailsModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.rma-details',
requires: ['Mb.model.rma.Detail'],
data: {
id: 0
},
stores:{
details: {
model: 'rma.Detail',
filters: [{
property: 'rma',
value: '{id}'
}]
}
}
});
Ext.define('Mb.model.rma.Detail', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'rma', type: 'int'},
(...)
],
proxy: { // cf. 2nd subsidiary question
(...)
}
});
The title of the view gets bound correctly to the value of id
.
But for the store, I get the errors:
[E] Ext.data.schema.Schema.lookupEntity(): No such Entity "rma.Detail".
Uncaught Error: No such Entity "rma.Detail".
I don't understand why the reference to the model (model: 'rma.Detail'
) is not recognized in the ViewModel. Using the MVC pattern I never needed to reference the model, I always referenced the store using a reference similar to rma.Details
.
The main question is: How do I need to declare the model rma.Details
in the ViewModel ?
Subsidiary questions are:
- Is this the correct way to set the value
id
in the View. ({xtype: 'rma-details', viewModel: {data: {id: id}}}
) ? - I'm used to define the proxy always in the store class. Here I don't have a store class anymore, because it is defined in the ViewModel. Is it correct to declare it in the model class like I did it above ?