Results 1 to 3 of 3

Thread: Dynamically change Proxy Reader root

  1. #1
    Sencha User brunofin's Avatar
    Join Date
    Jun 2014
    Location
    Brazil
    Posts
    19
    Answers
    2
    Vote Rating
    1
      0  

    Default Answered: Dynamically change Proxy Reader root

    I have a TreePanel which will have a maximum of 3 levels. First level is the tree's root, which will use a TreeStore to retrieve its children. These children will never be leaves, and they can use the same store of the root level to retrieve its children, which will be the final level of the tree and will always be leaves. These leaves can be retrieved by the same store, but in the JSON they have a different root (and URL, but that's a problem I already solved) than the tree's root, which needs to be changed after the second level is loaded.

    I am doing it like this in the TreeStore:

    Code:
    ...
    listeners: {
            beforeload: function(store, operation, eOpts) {   
                node = operation.node;
                
                if (node.internalId !== 'root' && !node.data.leaf) {
                    node.store.proxy.url = 'http://localhost:8000/cameras/' + node.getId() + '/';
                    node.store.proxy.reader.root = 'cameras'; // <= this actually changes the property, but still seems to not work
                }
            }
        }
    ...
    It seems to not work to just change the property and I suspect I must force the store to be reloaded somehow, but I don't know how. Can I have some directions, please?

  2. I could be wrong but you don't change the root of a reader after it's instance has been created.

    Try doing this way:

    Code:
    listeners: {
            beforeload: function(store, operation, eOpts) {   
                node = operation.node;
                
                if (node.internalId !== 'root' && !node.data.leaf) {
                    store.getProxy().url = 'http://localhost:8000/cameras/' + node.getId() + '/';
                    store.getProxy().setReader({
                        type : 'json',
                        root : 'cameras'
                     });
                }
            }
        }

  3. #2
    Sencha Premium Member glopes's Avatar
    Join Date
    Jan 2013
    Location
    Chicago
    Posts
    123
    Answers
    16
    Vote Rating
    32
      1  

    Default

    I could be wrong but you don't change the root of a reader after it's instance has been created.

    Try doing this way:

    Code:
    listeners: {
            beforeload: function(store, operation, eOpts) {   
                node = operation.node;
                
                if (node.internalId !== 'root' && !node.data.leaf) {
                    store.getProxy().url = 'http://localhost:8000/cameras/' + node.getId() + '/';
                    store.getProxy().setReader({
                        type : 'json',
                        root : 'cameras'
                     });
                }
            }
        }

  4. #3
    Sencha User brunofin's Avatar
    Join Date
    Jun 2014
    Location
    Brazil
    Posts
    19
    Answers
    2
    Vote Rating
    1
      0  

    Default

    Yes! setReader() worked perfectly! Thanks!

Posting Permissions

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