-
4 Aug 2011 3:55 AM #1
Cannot read property 'length' of undefined
Cannot read property 'length' of undefined
Hi!
I have copied this code from the nestedlist video tutorial and modified it a little. I am having this error :- Uncaught TypeError: Cannot read property 'length' of undefined
My JSon
My scriptCode:{ "items" : [ { "id": 1, "name": "Ed Spencer", "email": "ed@sencha.com" }, { "id": 2, "name": "Abe Elias", "email": "abe@sencha.com" } ] }
Code:Ext.regModel('listItem', { fields: ['id','name','mail'] }); listStoreItem = new Ext.data.TreeStore({ model: 'listItem', proxy: { type: 'ajax', url: '/public/models/contacts.json', reader: { type: 'tree', //Parceque c'est une NestedList root: 'items' } } }); Viewport = Ext.extend(Ext.NestedList, { fullscreen: true, title: "Contacts list", store: listStoreItem }) NestedListDemo = new Ext.Application({ name: "NestedList", launch: function() { viewport = new Viewport(); } });
Can anyone help me with that? Thanks
-
4 Aug 2011 4:15 AM #2
Unless it's a copy/paste typo you should have a closing curly bracket for your json and if you have your json in a file add the file extension:
the property in the proxy's reader should beCode:url: '/public/models/contacts.json'
instead of record: 'users'Code:root: 'items'
finally you should have nested data for your nested list. and try to avoid global variables in general.
-
4 Aug 2011 4:19 AM #3
Sorry for that i've been trying different possibilities and i forgot to put back the root line of code. I've just edited it but i still have the same error though. Other suggestions?
-
4 Aug 2011 4:45 AM #4
The video has the exact code as below when showing list arguments the first time. I am sorry but i don't understand when you say i should have nested data
Code:NestedListDemo.music_store = new Ext.data.TreeStore({ model: 'ListItem', proxy: { type: 'ajax', url: '/tracks/catalogue.json', reader: { type: 'tree', root: 'items' } } });
-
4 Aug 2011 5:33 AM #5
general problem store json objects ?
general problem store json objects ?
Could it be it is a general problem.
Coz I try long time already to store a jsonp object and it will not working.
I already opened a thread for a similar problem:
http://www.sencha.com/forum/showthre...ect-in-a-store
My data are nested data, too and after store command the store object has no data.
In the Sencha touch api abut the reader are some parts of examples, because I though I made something wrong with the regModels.
But i do not know it was not runing ....
-
4 Aug 2011 5:48 AM #6
-
4 Aug 2011 5:56 AM #7
not really an alternative
not really an alternative
The only way how I could store data was in an array.
Instead of "url" parameter I used the "data" parameter.
But this is non alternative for me, because I get JSON data fom a third system.
Maybe I could convert now the JSON in array.
But it is not a solution, too. It needs time on the client.
In the kitchensink demo JSON data will loaded, but then immediately displayed in an template.
I wondering, why no one else have this kind of problems ...
-
4 Aug 2011 7:52 AM #8
Well, the data in your initial post is flat. Your items don't have sub-items and you have not set the leaf property to true on any of them. Look at the data from the API docs:
http://dev.sencha.com/deploy/touch/d...estedList.html
-
5 Aug 2011 5:26 AM #9
It works
It works
Thanks you guys for your help. After hours of debugging and looking for something else to replace Sencha it works. I've put my data into a variable named 'data' that i call within the NestedList as root attribute like below. I've also added leaf to my data.
Code:var store = new Ext.data.TreeStore({ model: 'ListItem', root: data, proxy: { type: 'ajax', reader: { type: 'tree', root: 'items' } } });


Reply With Quote