PDA

View Full Version : How to retrieve the right Index



squalo
31 Mar 2014, 1:00 AM
Hi

on saving a model instance to my backend, I want to read the proper Index.


var s1 = record[0].save();
console.log(s1);
console.log(s1.data);
console.log(s1.data.Index);

But what I get is Zero, although in the logs before I see the correct Index value
(pls see pics. which are snapshots from chrome debugger F12))

log(s1):
48492
log(s1.data):
48493
log(s1.data.Index) = 0 !! :-/

I assume, I got trapped into this pitfall:
48497

So my question is: how to get the primary Index from database back, while Ext.direct.api create has done
by model.save()?
It is returned defnitely by the API , but I guess there are some asynchronicities.

Any hints?
Thx.

Farish
31 Mar 2014, 3:28 AM
Is Index a field in your model? in the 2nd snapshot, on top its showing Index: 0 in Object.

try using record.get('Index');

squalo
31 Mar 2014, 3:37 AM
yes, Index field is in the model.

using record.get('Index') had no remedy.

Maybe it got something todo with


idProperty: 'Index',

in the model?!

Farish
31 Mar 2014, 3:46 AM
it would help if you could post some code. what if you move your console.log() before the save()? Also, for newly created records, id is usually 0.

squalo
31 Mar 2014, 4:18 AM
For sure, newly created records got zero as index.
But i want to have the index the same value it becomes while the backend makes the sql-create.
So the method of my Ext.direct "create()" rotuine returns all saved model fields , but the Index is changed to the primary database key.

The pitfall was, that I believed , what chrome debugger shows me, was synchronously. But it is not.
Expanding the log row, all data below shown is from the timeslot while expanding and not logging itself!
(see pic No3)

Doing like this, I got the Index I want to.


var s1 = record[0].save();
console.log(s1.getId()); // => zero

grid.store.load({
scope: this,
callback: function(records, operation, success) {
console.log(s1.getId()); // => the new primary key index
}
});


Maybe I'm kinda conceptual wrong in doing so.

thx anyway