1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    164
    Vote Rating
    9
    Answers
    13
    in4p will become famous soon enough

      0  

    Default Answered: Stores and Associations

    Answered: Stores and Associations


    My application has the following structure:
    (i) Parent Store (a list of sites and urls)
    (ii) Child Store (entries from the URLs defined in the parent store)

    In the application I manually define the sites/urls in the parent store, and then kickoff a series of load calls via the proxy to pull the data entries for each site into the child store.

    I am trying to manually define a value for a field in the child store for each particular url, so I can identify which site it is from.

    E.g.
    Parent Store
    {name: 'a', site: 'http://....'}
    {name: 'b', site: 'http://....'}

    Child Store
    {someDataFromProxy: '....', siteName:'a'}
    {someDataFromProxy: '....', siteName:'a'}
    {someDataFromProxy: '....', siteName:'b'}

    (i)The site name I want in the child store isn't defined in the feed itself (so that's not an option) and (ii) for the life of me I can't figure out how to pass the siteName from the parent to the child store so that I can set it manually.

    Note on (ii) while it is possible for me to pass data from the parent to the child, because I am acting to update the child records manually using the 'load' event, I can only see the last value the was passed from the parent to the child store (i.e. by the time I am acting on the result of the load for site 'a', the data the child store has is site 'b' due to the async nature of the calls/processing).

    Someone please help! I can provide the code, but I figured the above explanation would be easier.

  2. Ok,
    So I've found a solution to my own problem which works, but is not ideal.

    For each record in the parent table, I create a new store instance of the child store and can thus pass values to the store itself (removing the issues of passing variables via the proxy and changing the proxy).

    It works, but I would imagine could have memory implications if the number of store instances created grows to large.

    Does anyone have a better solution?

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,547
    Vote Rating
    872
    Answers
    3566
    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


    It should be sending the id of the parent in the load call if I can remember correctly.

    If you are doing the load yourself then you could set the parent as an extra param on the proxy

    Code:
    child.getProxy().setExtraParam('parent', 'parent value')
    The extra param will be sent on all requests unless overridden from the load method.
    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
    Apr 2012
    Posts
    164
    Vote Rating
    9
    Answers
    13
    in4p will become famous soon enough

      0  

    Default


    Thanks Mitchell, unfortunately the problem isn't solved - I guess my initial description wasn't completely clear.

    I iterate through the parent records, and for each set the Proxy on the child store (each set of child items comes from a different source) and make the load call.
    Since all the child records are using the same store, by the time the load call comes back (async) I no longer have access to the proxy with which it was made - only the most recent proxy persists. Thus I lose the ability to retrieve the extraParam value for anything but the last set of child entries.

    Any other suggestions?

  5. #4
    Sencha User
    Join Date
    Apr 2012
    Posts
    164
    Vote Rating
    9
    Answers
    13
    in4p will become famous soon enough

      0  

    Default Potential Answer

    Potential Answer


    Ok,
    So I've found a solution to my own problem which works, but is not ideal.

    For each record in the parent table, I create a new store instance of the child store and can thus pass values to the store itself (removing the issues of passing variables via the proxy and changing the proxy).

    It works, but I would imagine could have memory implications if the number of store instances created grows to large.

    Does anyone have a better solution?

Thread Participants: 1

Tags for this Thread