1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    22
    Vote Rating
    0
    ron_stahl is on a distinguished road

      0  

    Default Unanswered: JSon Data not loaded into store data

    Unanswered: JSon Data not loaded into store data


    I have a form I want to load data into from a JSon store. Currently my application has a list that the user can click the disclose button on. This in turn calls a function with the internalId and creates a store and loads the data from the server into a json table with one row. When inspecting the store it appears to have no data but if you check the network you can see the call to the server and the json data returned.

    Code:
       ShowEditForm: function(recordID) {        var viewport   = this.getViewport(),
                topToolbar = viewport.down('titlebar[docked=top]'),
                newCard    = viewport.add({xtype: 'rdpmobile-woaddchange'});
    
    
            var store   = Ext.create('RDPMobile.store.WorkOrders.WorkOrder');
    
    
            store.load({ params: {WorkOrderID: recordID}});
    
    
            newCard.setRecord(store.getAt(0));
    
    
            viewport.setActiveItem(newCard);
    
    
            topToolbar.setTitle('Change Work Order');
    
    
        }
    Thanks for your help.
    Ron

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,656
    Vote Rating
    436
    Answers
    3108
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    This is usually due to the reader not setup correctly. Like is there a root... are the fields setup correctly
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,169
    Vote Rating
    28
    Answers
    83
    jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough

      0  

    Default


    Ron, store.load is going to fire off an ajax request, which is asynchronous.


    this is why newCard.setRecord(store.getAt(0)) fails. Because the store has no data at that point in time.

    What you need to do is setup the following logic in a "load" handler for the data store.
    Code:
            newCard.setRecord(store.getAt(0));
    
    
            viewport.setActiveItem(newCard);
    
    
            topToolbar.setTitle('Change Work Order');

    Jay Garcia @ModusJesus || Modus Create co-founder
    Ext JS in Action author
    Sencha Touch in Action author

    Get in touch for Ext JS & Sencha Touch Touch Training

    We are also working on Video-based Sencha Touch training: Check it out here.

  4. #4
    Sencha User
    Join Date
    Sep 2011
    Posts
    22
    Vote Rating
    0
    ron_stahl is on a distinguished road

      0  

    Default


    Jay,

    Would you have an example of this using MVC. I am not sure how to setup this up in the controller.

    Thanks
    Ron

  5. #5
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,656
    Vote Rating
    436
    Answers
    3108
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    You should either set a listener for the load event or use the callback method in the load method:

    Code:
    store.on('load', someFn, store);
    store.load();
    or

    Code:
    store.load({
        callback : someFn
    });
    My preference is the first.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  6. #6
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,169
    Vote Rating
    28
    Answers
    83
    jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    You should either set a listener for the load event or use the callback method in the load method:

    Code:
    store.on('load', someFn, store);
    store.load();
    should be:
    Code:
    ShowEditForm: function(recordID) {       
    // this == instance of controller
        //only register the load listener once!
        store.on('load', this.onStoreLoad, this);
        store.load({ params: {WorkOrderID: recordID}});
    }

    in your onStoreLoad:

    Code:
     
    onStoreLoad : function(store) {
           var viewport   = this.getViewport(),
                topToolbar = viewport.down('titlebar[docked=top]'),
                newCard    = viewport.add({xtype: 'rdpmobile-woaddchange'});
    
            newCard.setRecord(store.getAt(0));
            viewport.setActiveItem(newCard);
            topToolbar.setTitle('Change Work Order');
    }

    Jay Garcia @ModusJesus || Modus Create co-founder
    Ext JS in Action author
    Sencha Touch in Action author

    Get in touch for Ext JS & Sencha Touch Touch Training

    We are also working on Video-based Sencha Touch training: Check it out here.

  7. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,656
    Vote Rating
    436
    Answers
    3108
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    Quote Originally Posted by jay@moduscreate.com View Post
    should be:
    Code:
    // this == instance of controller
    store.on('load', this.onStoreLoad, this);
    store.load();

    in your onStoreLoad:

    Code:
    onStoreLoad : function(store) {
           var viewport   = this.getViewport(),
                topToolbar = viewport.down('titlebar[docked=top]'),
                newCard    = viewport.add({xtype: 'rdpmobile-woaddchange'});
    
            newCard.setRecord(store.getAt(0));
            viewport.setActiveItem(newCard);
            topToolbar.setTitle('Change Work Order');
    }
    Sorry I put an example of how to do it not actual code. Kind of wanted to guide him to figure it out.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for a lifetime."
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  8. #8
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,169
    Vote Rating
    28
    Answers
    83
    jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough

      0  

    Default


    calm down dude .

    he asked for an example in the context of a controller.

    Jay Garcia @ModusJesus || Modus Create co-founder
    Ext JS in Action author
    Sencha Touch in Action author

    Get in touch for Ext JS & Sencha Touch Touch Training

    We are also working on Video-based Sencha Touch training: Check it out here.

  9. #9
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,656
    Vote Rating
    436
    Answers
    3108
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    I am calm... everyone asks for example code but that doesn't seem to really teach people. Getting them to do some research seems to be giving a better impact.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  10. #10
    Sencha User
    Join Date
    Sep 2011
    Posts
    22
    Vote Rating
    0
    ron_stahl is on a distinguished road

      0  

    Default


    Mitchell,
    I understand your point I deal with people all the time looking for the problem to be solved for them without having to do some leg work or learning from an example given. If I am posting something I have usually spent several hours looking for an answer and though guidance is good sometimes a good working example can go a long way. A good example of this is the MVC example you posted. Before this I was still struggling with the setup and the connection of the files. Now, it is totally clear.


    Anyhow, I have tried the examples but when I set the store up with:

    Code:
    store.on('load',this.DataLoaded, this);
    I get the following error: Uncaught Error: [ERROR][RDPMobile.controller.WorkOrders.Monitor#getObservableId] Invalid unique id of 'WorkOrders.Monitor' for this object

    If i remove 'this' from the code then the 'this' context of the DataLoaded function is the store and not the controller.

    Thanks again for your help.
    Ron