1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    2
    Vote Rating
    0
    funkadamus is on a distinguished road

      0  

    Default Loading nested JSON into a TreeStore

    Loading nested JSON into a TreeStore


    I have a JSON file that I need to parse in to a TreeStore which will get passed to a TreePanel, however it's failing with any subdirectories.

    Example of my JSON input :
    Code:
    [{
     "text" : "review",
     "id" : "src\/review",
     "files" : [ "file.pdf", "file2.pdf" ],
     "folders" : [{
        "text" : "test",
        "id" : "src\/review\/test",
        "files" : ["file3.pdf"],
        "folders" : [],
        "leaf" : "true"
      }]
    }]
    My model and store is defined as :

    Code:
    Ext.define('TopDir', {
     model : 'Ext.data.Model',
     fields : ['text', 'id', 'files', 'folders'],
     hasMany : 'SubDir'
    });
    
     Ext.define('SubDir', {
      model : 'Ext.data.Model',
      fields : ['text', 'id', 'files'],
      belongsTo : 'TopDir'
     });
    Code:
    var store = Ext.create('Ext.data.TreeStore', {
      model : 'TopDir',
      proxy : {
        type : 'ajax',
        url : '/documents/grabjson',
      },
      root : { 
        id : 'src',
        text : "Documents", 
        expanded : true,
      },
      listeners : {
        load : function() {
          console.log(arguments);
        }
      }
    });
    And finally, my TreePanel

    Code:
      var tree = Ext.create('Ext.tree.Panel', {
            renderTo: 'tree-div',
            height: 650,
            width: 700,
    	store : store,
            title: 'Document Browser',
            useArrows: true
     });
    I basically tried to copy the "Drag and Drop Reordering" example while changing it around to work with my JSON output. With the above code, it will display the top-level directories yet gives an error when I try to expand anyone of them : "Uncaught TypeError: Cannot read property 'internalId' of undefined".

    I also got a bug with a previous revision that would again display the top-level directories, but whenever I would expand a node, it would be the same top-level entries within and would be a recursive loop of those regardless of how far I went down the tree.

    I'm fairly new to the ExtJS world so I'm not really sure where to go from here in debugging this. In my console output, it seems that the JSON is getting at least loaded, so my best guess is I'm doing something wrong with my models, although I'm not sure where to take it.
    Last edited by funkadamus; 10 May 2011 at 3:25 PM. Reason: Accidentally hit submit instead of preview post, still working on it.

  2. #2
    Sencha User
    Join Date
    Jul 2011
    Posts
    1
    Vote Rating
    0
    h0raz is on a distinguished road

      0  

    Default


    I have the same problem... Have you found a solution?

  3. #3
    Sencha User
    Join Date
    Dec 2009
    Posts
    9
    Vote Rating
    0
    marc.spoor is on a distinguished road

      0  

    Default cycles in tree data?

    cycles in tree data?


    I had the same problem, and it turned out that I had cycles in my "tree" data.

    In my case, the child of a node had the same id as the parent, which lead to a whole lot of confusion.

    If that's not the case for you, maybe you should post a stack trace.

  4. #4
    Sencha User
    Join Date
    Aug 2009
    Posts
    8
    Vote Rating
    0
    leomdg is on a distinguished road

      0  

    Default


    I'm in the same situation, please respond.

  5. #5
    Ext JS Premium Member Asken's Avatar
    Join Date
    Feb 2010
    Location
    sweden
    Posts
    118
    Vote Rating
    0
    Asken is an unknown quantity at this point

      1  

    Default


    You're not using the default notation 'children' in your json data.

    Try to do this:
    Code:
    ...
    proxy : {
        type : 'ajax',
        url : '/documents/grabjson',
        // set the reader to look for folders rather than children
        reader: {
            type: 'json',
            root: 'folders'
        }
      }
    ...

  6. #6
    Sencha User
    Join Date
    Nov 2010
    Posts
    3
    Vote Rating
    0
    yufulou is on a distinguished road

      0  

    Default


    Quote Originally Posted by Asken View Post
    You're not using the default notation 'children' in your json data.

    Try to do this:
    Code:
    ...
    proxy : {
        type : 'ajax',
        url : '/documents/grabjson',
        // set the reader to look for folders rather than children
        reader: {
            type: 'json',
            root: 'folders'
        }
      }
    ...
    How about if i have a json object like this


    {status:0,tree_data:[{ "text" : "review", "id" : "src\/review", "files" : [ "file.pdf", "file2.pdf" ], "folders" : [{ "text" : "test", "id" : "src\/review\/test", "files" : ["file3.pdf"], "folders" : [], "leaf" : "true" }] }]}

    This situation happened when i have some extra information received from server with one request. What should i do for displaying the "tree_data"?

Similar Threads

  1. Nested loading / nested saving in new data package
    By icflorescu in forum Ext: Discussion
    Replies: 16
    Last Post: 11 Oct 2013, 1:26 AM
  2. Replies: 1
    Last Post: 12 Apr 2011, 10:50 AM
  3. loading options for all combo boxes of a form in one nested JSON?
    By leizz in forum Ext 3.x: Help & Discussion
    Replies: 5
    Last Post: 18 Nov 2010, 11:40 AM

Thread Participants: 5