1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    55
    Vote Rating
    0
    Answers
    1
    twisted_zero is on a distinguished road

      0  

    Default 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:
    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:");
                    });
                }
            });
    my JSON-file:
    Code:
    {
        "users": [
            {
                "id": 123,
                "name": "TEST",
                "orders": [
                    {
                        "id": 789,
                        "total": 456
                    }
                ]
            }
        ]
    }
    when i run this, i get the follow output:
    Orders for undefined:
    TypeError: 'undefined' is not a function (evaluating 'user.orders()')
    how do i read this out?

  2. #2
    Sencha User
    Join Date
    Mar 2012
    Posts
    55
    Vote Rating
    0
    Answers
    1
    twisted_zero is on a distinguished road

      0  

    Default


    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?

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    47
    Vote Rating
    0
    Answers
    5
    BörnR is on a distinguished road

      0  

    Default


    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

  4. #4
    Sencha User
    Join Date
    Mar 2012
    Posts
    55
    Vote Rating
    0
    Answers
    1
    twisted_zero is on a distinguished road

      0  

    Default


    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...

  5. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    47
    Vote Rating
    0
    Answers
    5
    BörnR is on a distinguished road

      0  

    Default


    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

  6. #6
    Sencha User
    Join Date
    Mar 2012
    Posts
    55
    Vote Rating
    0
    Answers
    1
    twisted_zero is on a distinguished road

      0  

    Default


    yes, i know.
    but the code gets stuck before that.

  7. #7
    Touch Premium Member
    Join Date
    Nov 2011
    Posts
    37
    Vote Rating
    0
    bortron5000 is on a distinguished road

      0  

    Default


    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.

Thread Participants: 2

Tags for this Thread