Hi guys,
2 - I have defined a view (grid) bound to the viewmodel that I have defined. The vie is using the store of the view model:
3 - I create two views (two simpson grids):
4 - I create a button which, when clicked, will change the store data of the first grid viewmodel:
5 - Even if the views (grids) have two different viewmodels they share the same simpsonStore, and both grid are changed when I click on the button.
VERY SIMPLE ViewModel, WEIRD behavior
I have found at a really WEIRD behavior about view models, in particular stores of viewmodels.
I have a fiddle that describe the problem here: http://ift.tt/1uerqnU
But to sum up:
1 - I define a view model class with a store inside it like this
Code:
Ext.define('TestViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.myviewmodel',
stores: {
simpsonsStore: Ext.create('Ext.data.Store', {
fields:['name', 'email', 'phone'],
data:[
{'name': 'Lisa', "email":"lisa@simpsons.com", "phone":"555-111-1224"},
{'name': 'Bart', "email":"bart@simpsons.com", "phone":"555-222-1234"},
{'name': 'Homer', "email":"homer@simpsons.com", "phone":"555-222-1244"},
{'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"}
]
})
}
});
2 - I have defined a view (grid) bound to the viewmodel that I have defined. The vie is using the store of the view model:
Code:
Ext.define('TestSimpsonsGrid', {
extend: 'Ext.grid.Panel',
title: 'Simpsons',
height: 200,
width: 400,
viewModel: {
type: 'myviewmodel'
},
bind: '{simpsonsStore}',
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'phone' }
]
});
3 - I create two views (two simpson grids):
Code:
var grid1 = Ext.create('TestSimpsonsGrid', {
renderTo: Ext.getBody()
});
var grid2 = Ext.create('TestSimpsonsGrid', {
renderTo: Ext.getBody()
});
4 - I create a button which, when clicked, will change the store data of the first grid viewmodel:
Code:
var button = Ext.create('Ext.Button', {
text: 'Click to change the first grid viewmodel\'s store',
renderTo: Ext.getBody(),
margin: '10 10 10 63',
handler: function() {
grid1.getViewModel().getStore('simpsonsStore').loadData([{
"name": "Michel", "email":"michel@simpsons.com", "phone":"666-111-1224"
}]);
}
});
5 - Even if the views (grids) have two different viewmodels they share the same simpsonStore, and both grid are changed when I click on the button.
Is this the expected behavior ??
Thanks in advance !
VERY SIMPLE ViewModel, WEIRD behavior
Aucun commentaire:
Enregistrer un commentaire