PDA

View Full Version : Association problem



sravankumar
14 May 2012, 1:57 AM
hi,

I created a Student model as
Ext.define('AM.model.Student', {
extend: 'Ext.data.Model',
fields: ['rollId', 'studentName'],
associations: [
{type: 'hasMany', model: 'Courses',name: 'courses',associationKey:'listOfCourses',autoLoad: true}
]
});

and my courses model as
Ext.define('AM.model.Courses', {
extend: 'Ext.data.Model',
fields: ['id', 'name'],
belongsTo: 'Student'
});

and my Student controller as
Ext.define('AM.controller.Student', {
extend: 'Ext.app.Controller',
stores: [
'Student'
],
models: ['Student','Courses'],
views: [
'Student.List',
'Student.Edit'
],
init: function() {
this.control({
'studentlist': {
itemdblclick: this.editUser
},
'studentedit button[action=save]': {
click: this.updateUser
}
});
},
editUser: function(grid, record) {
console.log(record.get('studentName'));
var studentRecord=grid.getStore().getAt(0);
console.log(studentRecord.get('studentName'));
console.log(studentRecord.courses().getAt(0).get('name'));
var view = Ext.widget('studentedit');
view.down('form').loadRecord(record);
},
updateUser: function(button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();


record.set(values);
win.close();
this.getUsersStore().sync();
}
});

when i double click on student grid i want display course details in my console.


and server is giving response as

{"total":1,"data":[{"contactNo":"123","listOfCourses":[{"id":1,"name":"Maths"}],"listOfResults":[],"rollId":1,"studentName":"sravan"}],"success":true}but when access courses method on record it showing that no such function present error is coming.please help me.:-?thanks in advance.

14 May 2012, 5:37 PM
Approved the thread. Please post code within [ CODE ] [ /code ]tags in the future. it will increase your chances of getting support.