0
votes

I try to fill a treelist with remote data via a ajax proxy but the treelist shows only the first level and try to reload the sub levels even though the json response contain a complete tree structure. Fiddle link: https://fiddle.sencha.com/#view/editor&fiddle/33u9

When i try to expand the node 'SUB a' (or set the expanded property to true) the store trys to reload the node.

Why is the tree structure from the json response not honored?

Thanks in Advance.

The backend response looks like:

{
  "data": {
    "root": [
      {
        "leaf": true,
        "text": "Server"
      },
      {
        "leaf": true,
        "text": "Storage"
      },
      {
        "text": "SUB a"
        "children": [
          {
            "leaf": true,
            "text": "Modul A - 1"
          },
          {
            "leaf": true,
            "text": "Modul A - 2"
          }
        ],
      },
      {
        "leaf": true,
        "text": "Modul B"
      }
    ]
  },
  "success": true
}

The used reader config is

reader: {
  type: 'json',
  rootProperty: 'data.root',
  successProperty: 'data.success',
},
1

1 Answers

0
votes

After playing around i use the following workaround:

getNavigation: function() {
var me = this,
  tree = me.getView().down('navigationtree'),
  store = tree.getStore(),
  node = store.getRoot();

Ext.Ajax.request({
  url: '/getnav',
  method: 'POST',

  success: function(response) {
    var obj = Ext.decode(response.responseText),
      childs = obj.data.root;

    tree.suspendEvents();
    node.removeAll();
    childs.forEach(function(item) {
      node.appendChild(item);
    });
    tree.resumeEvents();
  },
  failure: function(response) {
    //debugger;
    console.log('server-side failure with status code ' + response.status);
  }
}).then(function() {
    //debugger;
  }
);

}

The funny things is that only the first level of the tree has to be added all following sub-levels are added automaticaly.