1. #1
    Sencha User
    Join Date
    Mar 2009
    Posts
    227
    Answers
    1
    Vote Rating
    0
    SchattenMann is an unknown quantity at this point

      0  

    Default Answered: Best Practive for Submiting/Getting List/Store Values

    Answered: Best Practive for Submiting/Getting List/Store Values


    Greetings

    I'm looking for the best way i can retrieve ( and later submit with the form ) a list content

    i know i can access the data using

    Code:
    mylist.getStore().getData()
    but the format the data is received makes it impossible to use JSON.stringify() on it.

    whats the best practice solution to achieve this?

    thanks

  2. You will need to iterate through the store and create an array of simple objects.

    Code:
    var data = [];
    
    store.each(function(record) {
        data.push(record.getData());
    });

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    856
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Are you needing to submit all the data or just data that changed?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

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

  4. #3
    Sencha User
    Join Date
    Mar 2009
    Posts
    227
    Answers
    1
    Vote Rating
    0
    SchattenMann is an unknown quantity at this point

      0  

    Default


    in this specific case i need to post all the data - i'm using the list as the lines in a invoice, so i need all data - although i would need to post only the changed data in a future situation.

    so if possible i would like to learn both situation buddy

    i swear i google as much as i could but i couldn't find a decent solution

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    856
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You will need to iterate through the store and create an array of simple objects.

    Code:
    var data = [];
    
    store.each(function(record) {
        data.push(record.getData());
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

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

  6. #5
    Sencha User
    Join Date
    Mar 2009
    Posts
    227
    Answers
    1
    Vote Rating
    0
    SchattenMann is an unknown quantity at this point

      0  

    Default


    thanks mitchellsimoens

    i was hopping i wouldn't need to do that. any plans on creating something like store.getData() ?

    anyway thanks for the replay. i got the idea and will test it tomorrow. you've been much helpfully.

  7. #6
    Sencha User
    Join Date
    Mar 2009
    Posts
    227
    Answers
    1
    Vote Rating
    0
    SchattenMann is an unknown quantity at this point

      0  

    Default


    Code:
    var store = this.parent.down('#LinhasDoc').getStore();
    
    var data = [];
    
    store.each(function(record) {
        data.push(record.getData());
    });
    
    JSON.stringify(data);
    will do the trick...not pretty but usefull

    thank you once again mitchellsimoens

    do you have any suggestion on how to submit this inside form.submit() or point me to a ST2 Forms Best Practice Guide? i've searched for it but can't find one single source of good information. theres seem to be to many differences between ST1 and ST2 and in opinions on how to Load/Submit/Validate data

  8. #7
    Sencha User
    Join Date
    Mar 2009
    Posts
    227
    Answers
    1
    Vote Rating
    0
    SchattenMann is an unknown quantity at this point

      0  

    Default


    so i guess i can do the following ?

    Code:
    var formdata = form.getValues()
    var storedata= [];  store.each(function(record) {     storedata.push(record.getData()); });
    
    formdata.push(storedata)
    
    form.submit({     params : formdata //can be a string or object });

  9. #8
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    856
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You can do something like:

    Code:
    form.submit({
        params : data //can be a string or object
    });
    That will add the params config to the field values.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

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

  10. #9
    Sencha User
    Join Date
    Mar 2009
    Posts
    227
    Answers
    1
    Vote Rating
    0
    SchattenMann is an unknown quantity at this point

      0  

    Default


    indeed

    i meant
    Code:
    formdata.mystore = storedata

  11. #10
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    856
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Quote Originally Posted by SchattenMann View Post
    so i guess i can do the following ?

    Code:
    var formdata = form.getValues()
    var storedata= [];  store.each(function(record) {     storedata.push(record.getData()); });
    
    formdata.push(storedata)
    
    form.submit({     params : formdata //can be a string or object });
    You will likely get an error when you do formdata.push as formdata will be an Object not an Array.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

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

Thread Participants: 1