PDA

View Full Version : get id of the inserted record



vladka
1 Nov 2011, 8:44 AM
Hello everyone.

got an create function:


onCreate: function(e, form) {
values = form.getValues();
this.getManifactorsStore().insert(0, values)
console.log(this.getManifactorsStore())


console.log(this.getManifactorsStore().data.items[0].data.id)
console.log(this.getManifactorsStore().data)
console.log(this.getManifactorsStore().data.items)
console.log(this.getManifactorsStore().data.items[0])
console.log(this.getManifactorsStore().data.items[0].internalId)
console.log(this.getManifactorsStore().data.items)
console.log(this.getManifactorsStore().data.keys)

}

first console.log, if look in browser console and go to
data.items.0.data.id - here we're got a id of new record
data.keys.0 - and here

but if log a this.getManifactorsStore().data.items[0].data.id (second console.log) - the id is null
and in all other console.logs the id of new record is a null or ext-record-1

how to get an added record id ?

find a simular theme without answer - http://www.sencha.com/forum/showthread.php?153025-Get-record-Id-after-insert-to-store

(http://www.sencha.com/forum/showthread.php?153025-Get-record-Id-after-insert-to-store)

ycuk
1 Nov 2011, 1:05 PM
I think that here so:


store.on('write', function(storeq, operation, eOpts){
console.log(operation);
});

but, it is a bad variant

vladka
1 Nov 2011, 1:28 PM
i'm found a solution!!

you're have to make a timeout.

so i you make code like this:



var showId = function(store) {
console.log('timeout')
console.log(store.data.items[0].data.id)
}
Ext.defer(showId, 2000, this, [store])

everythins is works fine.

thanks to the http://www.sencha.com/forum/member.php?324607-Romick for founded it




Maybe some one tell how to do it without timeout ?

ycuk
1 Nov 2011, 1:44 PM
timeout - For me doesn't approach

zmagyar
3 May 2012, 2:40 AM
Call store.load() after insertion and call your function in the callback. I.e.


store.load(function(records, operation, success){console.log(store.data.items[0].data.id) },this);