PDA

View Full Version : [FIXED] Creating JsonStore/JsonReader keeps throwing "Cannot read property'"



jeroenvduffelen
29 Jun 2010, 12:53 PM
I kept trying to set up a JsonStore and/or a separate JsonReader with different options but even with the example from the API docs:

My own code:


var readerBooks = new Ext.data.JsonReader({
root: 'books'
});


Example from the API docs:


var store = new Ext.data.JsonStore({
// store configs
autoDestroy: true,
url: 'get-images.php',
storeId: 'myStore',
// reader configs
root: 'images',
idProperty: 'name',
fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
});


I get Uncaught TypeError: Cannot read property 'prototype' of undefined on ext-touch-debug.js:11505

edspencer
29 Jun 2010, 1:13 PM
This is a dupe and has already been fixed for next release. You can use Ext.data.Store in the meantime but next release is imminent.

jeroenvduffelen
29 Jun 2010, 2:17 PM
ok, but how to set it up with a proxy than?

edspencer
29 Jun 2010, 2:24 PM
Like this:



new Ext.data.Store({
model: 'MyModel',
proxy: new Ext.data.LocalStorageProxy({
reader: {
type: 'json',
root: 'someroot'
}
})
})

jeroenvduffelen
30 Jun 2010, 4:29 PM
Ok, so i'm using this code now, which works fine:



this.state.books = new Ext.data.JsonStore({
autoLoad: true,
model: 'book',
proxy: {
url: '/books.json',
type: 'ajax',
reader: {
root: 'books',
type: 'json',
},
writer: {
type: 'json',
}
},
storeId: 'books',
});


But specifying the reader separately still kicks in with the same error.. is it me doing something that's not possible with:


var readerBooks = new Ext.data.JsonReader({
root: 'books',
idProperty: 'id',
fields: [
{name: 'id', type: 'string'},
{name: 'title', type: 'string'},
{name: 'slug', type: 'string'},
{name: 'author', type: 'string'},
{name: 'chapters', type: 'object'},
],
});

edspencer
30 Jun 2010, 4:44 PM
There is some magic internally which passes the model reference from the Store to the Proxy and its Reader + Writer. This is why we suggest using the object literal approach instead of directly instantiating your Reader as you have it above. Using the object literal allows the automatic linking to happen and enables lazy instantiation.