-
1 May 2012 5:29 AM #1
Unanswered: data reader MVC
Unanswered: data reader MVC
i am trying to implement the example from the data.reader.Reader
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.reader.Reader
i have added the models and a store.
this is my code to test it:
my JSON-file:Code:var store = Ext.create('Ext.data.Store', {model: "app.model.Dossier" }); store.load({ callback: function() { //the user that was loaded var user = store.getAt(0); console.log(user); console.log("Orders for " + user.get('name') + ":") user.orders().each(function(order) { console.log("Order ID: " + order.getId() + ", which contains items:"); }); } });
when i run this, i get the follow output:Code:{ "users": [ { "id": 123, "name": "TEST", "orders": [ { "id": 789, "total": 456 } ] } ] }
Orders for undefined:
TypeError: 'undefined' is not a function (evaluating 'user.orders()')
how do i read this out?
-
2 May 2012 2:59 AM #2
when i do in the callback-function the follow:
var user = store.getAt(0);
console.log(user);
i see the right object in raw/users/0:
Screen Shot 2012-05-02 at 12.57.11.png
can somebody help me out here?
-
2 May 2012 3:30 AM #3
i don't know Really, but if the function user.get('name') works, the try user.get('orders').each ...
Or if the function user.getId works, use user.getOrders().each
-
2 May 2012 3:50 AM #4
thanks for the respons.
i tried the getId() and that gives me "ext-record-3". ot the 123 that's in the json
so still nothing...
-
2 May 2012 3:57 AM #5
umm, i didn't see the link above you written.
if you did the same like the example, you forgot the orderItem in your models
-
2 May 2012 4:04 AM #6
yes, i know.
but the code gets stuck before that.
-
10 May 2012 8:05 AM #7
I could easily be wrong, but it looks to me like the data you want is nested another level deeper.
Try user.get('users')[0].name and see if that returns the name field. If so, then you can access orders in the same way.
Also, for issues like this, the Chrome debugger is very useful, try setting a break point at the problem line, and run snippets of code until you get the result you want. It'll save you lots of time.


Reply With Quote