redmagic
1 Aug 2012, 4:48 AM
Hi,
I've got a store with a rest proxy to communicate with the server.
My question is how do I update a added record with the id given to it by the server?
First, the record is added:
var newClass = Ext.create('SM.model.SchoolClass', {
name: name,
students: []
}); //Added without id
this.store.add(newClass);
this.store.sync();
The json going back and forth is as follows:
POST
{"id":null,"name":"testmij","students":[]}
Response
{"id":"b7ry8ina4ckr4k44x0ad5tpi6","name":"testmij","students":[]}
Then I handle the response on the stores write event:
this.store.on({
write: function (store, operation, options) {
this.handleResponse(operation);
},
scope:this
});
...
...
handleResponse: function (operation) {
if (operation.wasSuccessful()) {
switch (operation.action) {
case 'create':
var response = Ext.decode(operation.response.responseText);
this.addLocalClass(response.id, response.name, true);
this.getClassTabs().setActiveTab(response.id);
this.store.each(function(record) {
console.log(record.data.id,record.data.name)// This shows the added record, but without id
});
break;
case 'read':
break;
case 'update':
break;
case 'destroy':
this.removeLocalClass(operation.records[0].data.id);
break;
}
}
},
I would like to know what the proper way is to update the record with the id from the server.
Kind regards,
Arjen
I've got a store with a rest proxy to communicate with the server.
My question is how do I update a added record with the id given to it by the server?
First, the record is added:
var newClass = Ext.create('SM.model.SchoolClass', {
name: name,
students: []
}); //Added without id
this.store.add(newClass);
this.store.sync();
The json going back and forth is as follows:
POST
{"id":null,"name":"testmij","students":[]}
Response
{"id":"b7ry8ina4ckr4k44x0ad5tpi6","name":"testmij","students":[]}
Then I handle the response on the stores write event:
this.store.on({
write: function (store, operation, options) {
this.handleResponse(operation);
},
scope:this
});
...
...
handleResponse: function (operation) {
if (operation.wasSuccessful()) {
switch (operation.action) {
case 'create':
var response = Ext.decode(operation.response.responseText);
this.addLocalClass(response.id, response.name, true);
this.getClassTabs().setActiveTab(response.id);
this.store.each(function(record) {
console.log(record.data.id,record.data.name)// This shows the added record, but without id
});
break;
case 'read':
break;
case 'update':
break;
case 'destroy':
this.removeLocalClass(operation.records[0].data.id);
break;
}
}
},
I would like to know what the proper way is to update the record with the id from the server.
Kind regards,
Arjen