Results 1 to 2 of 2

Thread: Tree: how to load the root node and other root node issues

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    39
    Answers
    5

    Default Tree: how to load the root node and other root node issues

    Hi,

    Here is my code:
    Code:
    Ext.define('Menu', {
      extend: 'Ext.data.Model',
      fields: [
        { name: 'id', type: 'int' },
        { name: 'name', type: 'string' }
    ],
      proxy: {
        type: 'rest',
        url : '/rest/menu',
        reader: {
          type: 'json',
          root: 'data'
        }
      }
    });
    The store I'm using:
    Code:
    store = Ext.create('Ext.data.TreeStore', {
            model: 'Menu',
            nodeParam: 'id'
          });
    But it doesn't load anything (I checked the requests made by the browser: 0 for the targeted URL).
    So I force the load with a store.load(); ... but then, it requests 2 times the URL and so creates 2 children for the root node.

    So two problems:
    • the nodes are append to the root node. I want the fetched data to be the root node.
    • the double request
    Here is the JSON:
    Code:
    {"success":true,"errors":[],"data":{"id":"1","name":"Accueil"}}
    In addition, this node has children but they are not requested with the previous code. However, if I force the root node in the store with:
    Code:
    root: { id:1, name:'Home' }
    Then all the problems disappear and I can dynamically load child node, children of child nodes, etc.

    ...

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    You should specify the root node. You can hide the root via the rootVisible config on the Ext.tree.Panel.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

Posting Permissions

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