Hi
I am trying to iterate value from store .But am getting object has no method error in parent_group .can anybody tell how to get the name value in response .
This is my json response Group.json
Code:
"groups": {
"id": 10,
"parent_id": 100,
"name": "Main Group",
"parent_group": {
"id": 100,
"parent_id": null,
"name": "Parent Group"
},
"child_groups": [{
"id": 2,
"parent_id": 10,
"name": "Child Group 1"
},{
"id": 3,
"parent_id": 10,
"name": "Child Group 2"
},{
"id": 4,
"parent_id": 10,
"name": "Child Group 3"
}]
}
}
This is my Model GroupModel.js
Code:
Ext.define('GroupTest.model.GroupModel', { extend: 'Ext.data.Model',
config: {
fields: ['id', 'parent_id', 'name'],
proxy: {
type: 'ajax',
url: 'Group.json',
reader: {
type: 'json',
root: 'groups'
}
},
associations: [{
type: 'hasMany',
model: 'Group',
primaryKey: 'id',
foreignKey: 'parent_id',
autoLoad: true,
associationKey: 'child_groups'
}, {
type: 'belongsTo',
model: 'Group',
primaryKey: 'id',
foreignKey: 'parent_id',
associationKey: 'parent_group'
}]
}
});
This is My store GroupStore.js
Code:
Ext.define('GroupTest.store.GroupStore', {
extend : 'Ext.data.Store',
storeId : 'group',
model : 'GroupTest.model.GroupModel',
autoLoad : 'true',
proxy : {
type : 'ajax',
url : 'Group.json',
reader : {
type : 'json',
rootProperty : 'groups'
}
}
});
In App.js Trying to fetch the value
Code:
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
var store = Ext.create('GroupTest.store.GroupStore', {
model: "GroupTest.model.GroupModel",
});
]store.load({
callback: function()
{
var group=store.first();
console.log(group.parent_group().get('name'));
group.child_groups().each(function(rec){
console.log(rec.get('name'));
});
}
});
// Initialize the main view
//Ext.Viewport.add(Ext.create('GroupTest.view.Main'));
}
Thanks