1. #1
    Sencha User
    Join Date
    Oct 2011
    Location
    India
    Posts
    10
    Vote Rating
    0
    mukund1a is on a distinguished road

      0  

    Question How to retrive Ext.data.Store data in sencha

    How to retrive Ext.data.Store data in sencha


    var options_model=Ext.regModel('options_model', {
    fields: ['option1', 'status1','option2', 'status2','option3', 'status3','option4', 'status4']
    });
    var options = new Ext.data.Store({
    model: 'options_model',
    data: [
    { id: 1, option1: 'Alope', status1: 'true',option2: 'Option2', status2: 'false',option3: 'Option3', status: 'false',option4: 'Option4', status4: 'false' }
    ]
    });
    i have the above code now I want to get the various options values ..
    console.log(options.getById('option1'));
    console.log(options.getAt(2));
    undefine...............
    how to proceed help

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,994
    Vote Rating
    846
    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


    getById('option1') won't work because you are not looking for the correct id. getById(1) will get the record that id field is equal to 1.

    getAt(2) won't work because you only have one record loaded. getAt(0) will return the first (and only) record for you.
    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.

  3. #3
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,394
    Vote Rating
    22
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Quote Originally Posted by mukund1a View Post
    var options_model=Ext.regModel('options_model', {
    fields: ['option1', 'status1','option2', 'status2','option3', 'status3','option4', 'status4']
    });
    var options = new Ext.data.Store({
    model: 'options_model',
    data: [
    { id: 1, option1: 'Alope', status1: 'true',option2: 'Option2', status2: 'false',option3: 'Option3', status: 'false',option4: 'Option4', status4: 'false' }
    ]
    });
    i have the above code now I want to get the various options values ..
    console.log(options.getById('option1'));
    console.log(options.getAt(2));
    undefine...............
    how to proceed help
    If you want to get a record by its id you first have to set the "idProperty" on your model, that, looking on how you are trying to get your record, should be "option1" even if would be more correct to set it on the id property that, you have defined in your data, but not in your model.

    However, to set the idProperty to the field "option1", you only need to edit your model like follows:

    Code:
    var options_model=Ext.regModel('options_model', {
         idProperty: 'option1',
         fields: ['option1', 'status1','option2', 'status2','option3', 'status3','option4', 'status4']
    });
    In this way calling

    Code:
    console.log(options.getById('option1'));
    You will be able to retrieve your first an only record.

    Instead, console.log(options.getAt(2)), exactly like Mitchell told you, doesn't returns you anything, because it suppose that you have 3 records loaded in your store but you actually have only 1 record.

    Hope this helps.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    CEO at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    http://www.tux-components.com/


  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,994
    Vote Rating
    846
    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


    fyi... idProperty defaults to 'id' and you don't actually need to add it to your fields.
    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.

  5. #5
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,394
    Vote Rating
    22
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    fyi... idProperty defaults to 'id' and you don't actually need to add it to your fields.
    True if he have to get the value by the id property, but I just wanted clear that he can set a different id field if he need it.

    However, reading again my example I've noticed I made confusion, because your fields name and data values are almost the same, so to get the first record, by setting the "idProperty" on your model to "option1" you should write

    Code:
     
    options.getById('Alope');
    Hope this helps.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    CEO at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    http://www.tux-components.com/