-
20 Nov 2012 10:14 AM #1
Binding combobox to a inner object
Binding combobox to a inner object
Hi, this is my json from server:
I need to bind the combobox to the field: paciente.id and paciente.nome, respectively to valueField and displayField.Code:[ { "consulta_id": 23752, "convenio_id": 1, "data": "2012-07-11", "id": 36569, "paciente": { "nome": "Alvasole", "id": 12 }, "tipo": 1 }, { "consulta_id": 23753, "convenio_id": 61, "data": "2012-07-11", "id": 36579, "paciente": { "nome": "Felintoi", "id": 33 }, "tipo": 1 } ]
This combo will only have 1 record on its store.
I get this work in this way:
But i think that may have a better way.Code:this.getForm().loadRecord(rec); combo.store = Ext.create('Ext.data.Store', { fields: ['id', 'nome'], data : [ rec.get('paciente') ] });
-
21 Nov 2012 4:14 AM #2
Hi larini,
You may use a Model for your Store and in your fields you use the mapping property. Like below:
Code:Ext.define('ModelName', { extend: 'Ext.data.Model' ,fields: [ {name: 'id', type: 'int', mapping: 'paciente.id'}, {name: 'age', type: 'int', convert: null}, {name: 'phone', type: 'string'}, {name: 'alive', type: 'boolean', defaultValue: true, convert: null} ] }); var store = Ext.create('Ext.data.Store', { model: 'ModelName' ,autoLoad: true ,proxy: { type: 'ajax' ,url: 'page.php' // Define your PHP file ,reader: { type: 'json' ,root: 'root' } } });I am sorry my english, I am learning yet
Portuguese blog: http://wessdevel.blogspot.com.br/
Twitter: @wlegolas
-
21 Nov 2012 4:29 AM #3
I already tried this, but is not working. It looks like there must be a stored already defined in the combobox. How I must declare the combobox control ?
-
21 Nov 2012 7:34 AM #4
The Store of combobox should be defined when you create him. Set your Model, Store and after set your ComboBox with the Store equal my example.It looks like there must be a stored already defined in the comboboxI am sorry my english, I am learning yet
Portuguese blog: http://wessdevel.blogspot.com.br/
Twitter: @wlegolas
-
21 Nov 2012 7:56 AM #5
Ok, but I thought that was an automatic way to do that. Something that runs after a form load and fills the store automatically.
-
21 Nov 2012 3:50 PM #6
Hi larini,
If I understand right, you are editing a record and the value in your ComboBox not being selected. So yor doubt is "How do I select a value in the registry editing in Combo?". It would this your question?
Would have like to post the code of your ComboBox and your Store?I am sorry my english, I am learning yet
Portuguese blog: http://wessdevel.blogspot.com.br/
Twitter: @wlegolas


Reply With Quote