mardi 9 septembre 2014

ViewModel Links with multilevel JSON

Hallo,

I use a multilevel JSON to populate couple of textfields. Beside giving them an initial value I also would like to save any changes made to them. For this I use the 'links' option in my viewModel.


The value binding works for the initial value but when I make a value change to the field the 'theRecord' record is not updated but a new object is added to it. (record.level1.field1 for example and not as I would expect record.data.level1.field1)


This only happends when I use a binding like this :'{theRecord.level1.field1}'.

When I don't use any levels ('{theRecord.field1}') this isn't an issue. The data object gets updated and dirty is true.


So I'm wondering why does the 'read' part of the binding work with levels but the 'write' part does not?


Model:



Code:



Ext.define('xml.model.Patdata', {
extend: 'Ext.data.Model',

proxy: {
type: 'ajax',
url: 'resources/patdata.json',
reader: {
type: 'json',
record: 'PATIENTDATA'
},
writer: {
type: 'json',
expandData: true
}


}
});

I don't have fields because I want to use the new dynamic feature in Extjs5. There are 50+ fields in the JSON.

VM:



Code:



Ext.define('xml.view.main.MainModel', {
extend: 'Ext.app.ViewModel',


alias: 'viewmodel.main',



session: true,


links: {
Patdata: {
type: 'xml.model.Patdata',
id: 1,
session: true
}
}



});

mainView:

Code:



xtype: 'textfield',
bind: {
value: {
bindTo: '{Patdata.PATIENT_DATA.FIRST_NAME}' //write does not work
// bindTo: '{Patdata.FIRST_NAME}' // write does work but read does not
}
}





ViewModel Links with multilevel JSON

Aucun commentaire:

Enregistrer un commentaire