Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext JS Premium Member stevil's Avatar
    Join Date
    Nov 2007
    Location
    Denver, CO
    Posts
    1,045
    Vote Rating
    9
    stevil will become famous soon enough

      0  

    Post [B2] TreeStore constructor error with nested root in JSON reader

    [B2] TreeStore constructor error with nested root in JSON reader


    With the following proxy and store setup to initialize a TreePanel:

    PHP Code:
    // I know this may be verbose (I can specify a proxy config in the store config, etc.), 
    // am breaking it out this way for debugging purposes
    //
    // Field and path names have been changed to protect the innocent. 
     
    Ext.regModel('MyTree', {
        
    fields: [ { name'parentID'type'int' },
            { 
    name'leaf'type'boolean' }, 
            { 
    name'nodeHref'type'string' }, 
            { 
    name'nodeType'type'string' }, 
            { 
    name'nodeText'type'string' }, 
            { 
    name'nodeCategoryPath'type'string' }, 
            { 
    name'nodeCategoryType'type'string' }
        ]
    });
     
    var 
    proxy = new Ext.data.AjaxProxy({
        
    url'mytree.json',
        
    reader: {
            
    type'json',
            
    root'myTree.data' // in the JSON result, nodes appear at this path
        
    }
    });
     
    var 
    store = new Ext.data.TreeStore({
        
    nodeParam'nodeID',
        
    parentField'parentID',
        
    model'MyTree',
        
    proxyproxy,
        
    root: {
            
    expandedtrue
        
    }
    }); 
    When I attempt to create the store, I get an exception with the message:

    PHP Code:
    TypeErrorResult of expression 'obj.myTree' [undefinedis not an object
    If I remove the ".data" suffix from the reader's root config, this error does not occur. (Of course, the store doesn't work either as id doesn't point to the correct location in the JSON). This also worked with TreeLoader prior to Ext 4.0.

    This exception is thrown in Ext.data.TreeStore.setRootNode:

    PHP Code:
    setRootNode: function(root) {
        var 
    me this,
        
    proxy me.getProxy(),
        
    reader proxy.getReader(),
        
    childrendataRoot;
     
        
    root root || {}; 
        if (!
    root.isNode) {
     
     
        
    Ext.applyIf(root, {
            
    idme.defaultRootId,
            
    text'Root',
            
    allowDragfalse
        
    });
     
        
    // Fails when running the anonymous getRoot accessor
        
    dataRoot reader.getRoot(root); 
        
    root Ext.ModelMgr.create(rootme.model);

    stevil
    Last edited by stevil; 12 Apr 2011 at 9:37 AM. Reason: formatting

  2. #2
    Ext JS Premium Member stevil's Avatar
    Join Date
    Nov 2007
    Location
    Denver, CO
    Posts
    1,045
    Vote Rating
    9
    stevil will become famous soon enough

      0  

    Cool


    Replacing the indicated line in setRootNode() with:

    PHP Code:
    try { dataRoot reader.getRoot(root); } catch (edr) { dataRoot null }; 
    allows me to get past the problem of creating the store.

    Edit: but then it never gets called again, because the root config gets turned into a root node!

    Edit 2: and

    PHP Code:
    useSimpleAccessorstrue 
    on the reader config removes the need to catch the exception above.
    Last edited by stevil; 12 Apr 2011 at 11:09 AM. Reason: new information has come to light, man

Similar Threads

  1. Problem getting nested Json in Store (different root for each Model)
    By nerdbert in forum Sencha Touch 1.x: Discussion
    Replies: 0
    Last Post: 3 Dec 2010, 6:48 AM
  2. [SOLVED]Json reader with grid won't display nested json
    By josh803316 in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 4 Mar 2009, 6:29 PM
  3. [SOLVED] Formpanel and json nested data -> external reader?
    By CircleCode in forum Ext 2.x: Help & Discussion
    Replies: 13
    Last Post: 17 Feb 2009, 8:07 AM
  4. Nested JSON Reader HELP !!!
    By bhaveshbhatkar in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 24 Aug 2008, 6:35 AM

Tags for this Thread