PDA

View Full Version : [CLOSED]Store's getById() doesn't work correct



t800t8
29 Sep 2009, 8:40 PM
Ext version tested:


Ext 3.0



Browser versions tested against:


IE8



Operating System:


WinXP Pro



Description:
I do a check before adding a new record to the store by getById() as in the test case but after adding new record, this.selectorView.store.getById(newTheme.id)) still equals 'undefined'.

If I do the check by this.selectorView.store.findExact(), it works properly. I DID set value for store's idProperty.

Test Case:

if (typeof(this.selectorView.store.getById(newTheme.id)) == 'undefined') {

this.selectorView.store.add([new this.ThemeRecord(newTheme)]);

}

Condor
29 Sep 2009, 9:26 PM
There is a difference between a field named 'id' and the id of a record.

You are not specifying the id when creating a record, e.g.

new this.ThemeRecord(newTheme, newTheme.id)

evant
29 Sep 2009, 9:29 PM
You need to provide more information, for example your store is configured and how the records are getting there, but what Condor is saying is likely correct.

t800t8
29 Sep 2009, 9:58 PM
Thanks. That's help :)

But I expect that when I set 'idProperty' for store, it should automatically find and use that property in the record's data as id. Should I file a request?

evant
29 Sep 2009, 10:10 PM
Ext.onReady(function(){

var s = new Ext.data.Store({
reader: new Ext.data.JsonReader({
id: 'f1',
root: 'data'
}, ['f1'])
});
s.loadData({
data: [{
f1: 1
},{
f1: 2
},{
f1: 3
},{
f1: 4
}]
});
console.log(s.getById(1));

});



It already does this.

t800t8
30 Sep 2009, 1:48 AM
Nope, the problem doesn't happen if you load data this way. It happens after you add new record (see my first post).

Actually, I expect that when the record model should have 'id' or 'idProperty' property, if it's true, the field is an id.



recordModel = [
{name: 'id', type: 'int', id: true},
{name: 'name'},
{name: 'state'}
]
so when you add a new record to the store,store.add([new ThemeRecord(newTheme)]) is enough

Condor
30 Sep 2009, 1:57 AM
Using the record constructor to create a records doesn't use the reader in any way (so the idProperty isn't used).

Either specify the id in the record constructor (like I showed before) or use the reader, e.g.

var r = store.reader.readRecords({myroot: [newTheme]});
store.add(r.records);

evant
30 Sep 2009, 2:39 AM
Once again, Condor is correct. If you're adding a single record, you need to specify the second parameter (the id).