Juanito
7 Apr 2011, 9:40 AM
I am loading data into a store using loadData. My JSON records all have an id property but when I use Store.indexOfId to find a record, I get -1 because the ids aren't what I expect them to be, they are Ext's generated IDs.
Here's a sample record array I'm passing into Store.loadData()
[
{"summary":"Philosophy professor Bill Ramseys feature Making The Grade: Why you may be wrong about whats right about chipping[No. 191] drew various comments from readers,...",
"id":1023,
"author":"admin",
"title":"The Chipping Contradiction",
"isHeadline":true,
"image":"/9j/4AAYH//Z"},
{"summary":"Ozturk on Meru in Nanda Devi National Park, in the Himalaya of northern India. Photo by Jimmy Chin. Renan Ozturk, leading climber and filmmaker, was involved...",
"id":1021,
"author":"Alison Osius",
"title":"Renan Ozturk seriously injured, but on upswing",
"isHeadline":false,
"image":"/9j/4AAQ3P/Z"}]
Here's my Model definition
Ext.regModel('ArticleListModel', {
fields: [
{name:'author',type: 'string'},
{name:'id',type: 'number'},
{name:'summary',type: 'string'},
{name:'image',type: 'string'},
{name:'title',type: 'string'}
{name:'isHeadline',type: 'boolean'}
]
});
When I look at one of the records, its internalId is ext-record-{number}. I thought I had a bug in my code somehwere but here's why I think it's Sencha's bug. When I call
store.findExact('id', this._article.articleId)
Everything works. However, if I call
store.indexOfId(this._article.articleId)
I get -1 back;
So I dug into the code:
Store.loadData calls Ext.ModelMgr.create(record, model) without passing in an ID which is expected by that method. Ext.ModelMgr.create ends up calling the Model constructor without an ID, therefore, giving it a made up ID.
Here's a sample record array I'm passing into Store.loadData()
[
{"summary":"Philosophy professor Bill Ramseys feature Making The Grade: Why you may be wrong about whats right about chipping[No. 191] drew various comments from readers,...",
"id":1023,
"author":"admin",
"title":"The Chipping Contradiction",
"isHeadline":true,
"image":"/9j/4AAYH//Z"},
{"summary":"Ozturk on Meru in Nanda Devi National Park, in the Himalaya of northern India. Photo by Jimmy Chin. Renan Ozturk, leading climber and filmmaker, was involved...",
"id":1021,
"author":"Alison Osius",
"title":"Renan Ozturk seriously injured, but on upswing",
"isHeadline":false,
"image":"/9j/4AAQ3P/Z"}]
Here's my Model definition
Ext.regModel('ArticleListModel', {
fields: [
{name:'author',type: 'string'},
{name:'id',type: 'number'},
{name:'summary',type: 'string'},
{name:'image',type: 'string'},
{name:'title',type: 'string'}
{name:'isHeadline',type: 'boolean'}
]
});
When I look at one of the records, its internalId is ext-record-{number}. I thought I had a bug in my code somehwere but here's why I think it's Sencha's bug. When I call
store.findExact('id', this._article.articleId)
Everything works. However, if I call
store.indexOfId(this._article.articleId)
I get -1 back;
So I dug into the code:
Store.loadData calls Ext.ModelMgr.create(record, model) without passing in an ID which is expected by that method. Ext.ModelMgr.create ends up calling the Model constructor without an ID, therefore, giving it a made up ID.