View Full Version : Getting ID after create

21 Dec 2011, 6:15 AM
I create a record, insert it to the store and make a sync. The create-url is called. I got an answer (the record with the id), but the record in the store do not have a changed id. When I change this record, the Update-url is called, but the ID is empty. Why? How to change the id of the record to the given db-id (from the response of the create-url).

{'success': true, 'message': 'Created record', 'data': {'id': 1, 'text': 'text'}}
(I also tried to answer just "1".)



Ext.define('My.store.ds', {
extend: 'Ext.data.Store',
model: 'My.model.ds',
proxy: {
type: 'ajax',
api: {
read: '/ds/ReadK',
create: '/ds/CreateK',
update: '/ds/UpdateK' },
reader: {
type: 'json',
root: 'ds',
successProperty: 'success' } },
remoteSort: true });

Ext.define('My.model.ds', {
extend : 'Ext.data.Model',
fields : [{ name : 'id', type : 'int', useNull : true }, 'text'] });

var record = Ext.create('My.model.ds');
record.data.id = null;
var s = Ext.getStore('ds');
s.insert(0, record);

21 Dec 2011, 6:42 AM
I don't like it, but it works, when I add the write listener to to store:

listeners: {
write: function (store, operation, eOpts) {
if (operation.action == 'create')
operation.records[0].data.id = operation.response.responseText;

Now I just response the id, when the create-url is called.