-
13 Sep 2012 1:00 PM #1
Unanswered: How to define the Model and Load the store for this Complex Json
Unanswered: How to define the Model and Load the store for this Complex Json
{
- field1: "value1",
- field2: "value2",
- field3: "value3",
- field4: "value4",
- field5: "value5",
-details: {- field6: "value6",
- field7: "value7",
- field6: "value6",
- }
- -
adddetails: [- -
{- field8: "value8",
- field9: "value9",
- field8: "value8",
- }
- -
{- field8: "value10",
- field9: "value11",
- field8: "value10",
- }
- -
- ]
-
13 Sep 2012 1:11 PM #2
You can use the mapping property of the fields to specify the path from the value will be extracted.
For the array you can create a one-to-many association. You can find more information on the documentation: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.ModelCode:Ext.define('MyApp.model.MyModel',{ extend : 'Ext.data.Model', fields : [ {name:'field6',mapping:'details.field6'}, {name:'field7',mapping:'details.field7'} ] });
Regards
-
13 Sep 2012 1:20 PM #3
Thanks for the reply .But in the store it is not getting the values.
-
14 Sep 2012 8:03 AM #4Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,185
- Vote Rating
- 194
- Answers
- 433
Your entries 'details' is an object and you 'adddetails' is an array
Was this Intentional?
so you would need to use:
You can also use the qualifier in you field/data index when using objectsCode:{ mapping:'adddetails[0].fieldx' }
If you need to separate.Code:dataIndex: 'details.field6' fields:['details.field6'],
Scott.
-
14 Sep 2012 6:51 PM #5
Ext.define('app.model.MYModel', {
extend: 'Ext.data.Model',
id:'MYModel',
config: {
dataIndex: 'details.filed6',
fields: [
{
name: 'filed1',
type:'string'
},
{
name: 'filed2',
type:'string'
},
{
name: 'filed3',
type:'string'
},
{
name: 'filed4',
type:'string'
},
{
name: 'filed4',
type:'string'
},
{
name: 'filed6',
type:'string'
}
]
}
});
Is the above model is fine for the JSOn mentioned above?
-
15 Sep 2012 2:59 AM #6Sencha - Community Support Team
- Join Date
- May 2012
- Location
- Istanbul
- Posts
- 1,331
- Vote Rating
- 76
- Answers
- 124
@nannuru,
your model are not valid, the valid model for above mentioned json are -
Code:Ext.define('MainModel', { extend:'Ext.data.Model', fields:[ {name:'field1'}, ...................., {name:'field5'}, {name:'field6', mapping:'details.field6'}, {name:'field7', mapping:'details.field7'} ], hasMany:{model:'Address', name:'adddetails'} }) Ext.define('Address', { extend:'Ext.data.Model', fields:[ {name:'field8'}, {name:'field9'} ], belongsTo:'MainModel' })
sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.
-
15 Sep 2012 4:34 AM #7
code:-
Code:Ext.define('app.model.MYModel', { extend: 'Ext.data.Model', id:'MYModel', config: { dataIndex: 'details.filed6', fields: [ { name: 'filed1', type:'string' }, { name: 'filed2', type:'string' }, { name: 'filed3', type:'string' }, { name: 'filed4', type:'string' }, { name: 'filed4', type:'string' }, { name: 'filed6', type:'string', mapping: 'details.filed6' } { name: 'filed7', type:'string', mapping: 'details.filed7' } ] } });
Store:-
Code:Ext.define('app.store.MYStore', { extend: 'Ext.data.Store', id:'MYStore', config: { model: 'app.model.MYModel', proxy: { type: 'ajax', url: /tempjson reader: { type:'json', }, writer: { type : 'json', writeAllFields: true, nameProperty : 'mapping', successProperty : 'success' } }, autoLoad: true, timeout: 5000, }});
View:-
Controller:=Code:Ext.define('app.view.MYPanel', { extend: 'Ext.form.FormPanel', xtype: 'MYFormPanel', id:'MYFormPanel', config: { items: [ { xtype: 'fieldset', id:'myfiledset', title: 'MyJSONfirstlist', } items: [ { xtype: 'textfield', label: 'field1:', name: 'field1', },]}, { xtype: 'fieldset', id:'myfiledset', title: 'MyJSONfirstlistdetails', } items: [ { xtype: 'textfield', label: 'field6:', name: 'field6', }, xtype: 'textfield', label: 'field7:', name: 'field7', }]},
filed6 and filed 7 are not getting loaded.Code:this.getMyform().setRecord(Ext.getStore("MYStore").getAt(0));


Reply With Quote