Results 1 to 3 of 3

Thread: Store reading multiple roots

  1. #1
    Sencha User tf.alves's Avatar
    Join Date
    Feb 2010
    Location
    Portugal
    Posts
    54
    Answers
    3
    Vote Rating
    0
      0  

    Default Answered: Store reading multiple roots

    I have a JSON like the following:

    {"olditems":"true","items":[]}
    I assigned the reader of my store with the root 'items' because I want this items to populate my template. But I also want to read my olditems value, how can I do this?
    I have tried many things, but, if I set the root as "items" I can no longer have access to "olditems"

    All I need is to access this property in the listener 'load', so I can add an extra record to the store in case this property is set to true.

    Can anyone help me? I'm sure this one is quite easy to solve, but I've been googling around for the last couple of hours and this is driving me crazy!

  2. You can add this to the Store:

    Code:
    getOldItems: function() {
        var reader = this.proxy.reader;
    
        return reader.createAccessor('olditems')(reader.rawData);
    }
    reader.createAccessor creates a function that can look for the key you pass it, in this case you want to look for 'olditems'. You then execute that function passing in the raw data and the reader will then return that value.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,317
    Answers
    3882
    Vote Rating
    1291
      0  

    Default

    You can add this to the Store:

    Code:
    getOldItems: function() {
        var reader = this.proxy.reader;
    
        return reader.createAccessor('olditems')(reader.rawData);
    }
    reader.createAccessor creates a function that can look for the key you pass it, in this case you want to look for 'olditems'. You then execute that function passing in the raw data and the reader will then return that value.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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
    Apr 2012
    Posts
    5
    Vote Rating
    0
      0  

    Default JSON with 2 roots to be read

    Hi ,
    A small clarification. Is it possible to read such a structure to a extJs store ??
    Ur suggestion will be of great help.
    "results": [{
    "time",
    "values": [
    {
    "x":
    "y":
    },
    {
    "x":
    "y":
    },
    {
    "x":
    "y":
    }
    ]

    },
    {
    "time",
    "values": [
    {
    "x":
    "y":
    },
    {
    "x":
    "y":
    },
    {
    "x":
    "y":
    }
    ]
    }]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •