Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn extra data besides tree data from ExtJS TreeLoader dataUrl?
    primarykey
    data
    text
    <p>I asked this question in the Ext JS forums, but I received no responses, so I am asking here.</p> <p>I have a TreePanel (code below) that uses a TreeLoader and an AsyncTreeNode. In my API method specified by the TreeLoader's dataUrl, I return a JSON array to populate the tree.</p> <p>This works great, of course. However, I need to return an additional item--an integer--in addition to the array, and I need to display that value somewhere else in my UI. Is this possible? If not, what else would be a good solution?</p> <p>Here's the code I have currently:</p> <pre><code>tree = new Ext.tree.TreePanel({ enableDD: true, rootVisible: false, useArrows: true, loader: new Ext.tree.TreeLoader({ dataUrl: '/api/method' }), root: new Ext.tree.AsyncTreeNode() }); </code></pre> <p>I want to return one single integer value for the entire response--not per node. Basically my API method will create a database record, and I need to return a value from that database record.</p> <p><em>EDIT</em> Thanks to Mike, I have solved this problem. I extended the Ext.tree.TreeLoader class like so:</p> <pre><code>TreeLoaderWithMetaData = Ext.extend(Ext.tree.TreeLoader, { processResponse : function(response, node, callback) { var json = response.responseText; try { var o = eval("("+json+")"); metaData = o.shift(); node.beginUpdate(); for(var i=0, len=o.length; i&lt;len; i++) { var n = this.createNode(o[i]); if (n) { node.appendChild(n); } } node.endUpdate(); if(typeof callback == "function") { callback(this, node); } } catch (e) { this.handleFailure(response); } } }); </code></pre> <p>And then I can reference variables in the meta data like public members: metaData.my_variable1, metaData.my_variable2. My AJAX data from the server just has an extra array item:</p> <pre><code>[{"my_variable1":"value1","my_variable2":"value2"},{"id":"node1","text":"Node 1",children:[{"id":"node1nodeA","text":"Node 1 Node A"}]] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload