Treeloader extensions that support the array values contained in the JSON object returned by Josn-plugin

Source: Internet
Author: User
Tags config json zip

Struts2 's Josn plugin Josn-plugin is convenient for us to develop the EXTJS program, but every time he returns the data format is returned as an object, the object can contain other formats of data, such as arrays.

This is the general return format.

JS Code

{"Root": [{Address]: "Shenzhen", "Company": "Bank of", "Manager": "True", "name": "Jack", "Password": "A", "userid": "8ad08c8323eeb3ba0123eeb3c6e20001", "username": "A", "Zip": "518000"},{"Address": "Dongjing", "Company": "Bank of Japan "," Manager ":" false "," name ":" Jack Cheng "," Password ":" B "," userid ":" 8ad08c8323eeb3ba0123eeb3c6e20002 "," username ":" B "," Zip ":" 518000 "}]," Totalproperty ": 2}

Struts2 background configuration is

XML code

<action name="getUsers" class="userAction" method="getUsers">
   <result type="json">
     <param name="root">
     page
     </param>
     <param name="excludeNullProperties">
     true
     </param>
     <param name="includeProperties">
     root.*,totalProperty 
     </param>
   </result>
</action>

And when we do the tree (Treepanel), the data returned by the server is the form of an array object.

JS Code

[{address]: "Shenzhen", "Company": "Bank of", "Manager": "True", "name": "Jack", "Password": "A", "userid": " 8ad08c8323eeb3ba0123eeb3c6e20001 "," username ":" A "," Zip ":" 518000 "},{" Address ":" Dongjing "," Company ":" Bank of Japan " , "Manager": "false", "name": "Jack Cheng", "Password": "B", "userid": "8ad08c8323eeb3ba0123eeb3c6e20002", "username": "b "," Zip ":" 518000 "}]

But Json-plugin does not support returning this format directly, so we can modify the Treeloader handler function

JS Code

The

//treeloader extension, which supports the array values contained in the JSON object returned by Josn-plugin
Ext.tree.JsonPluginTreeLoader = function (config) {
This.rootname = ' root ';
Ext.tree.JsonPluginTreeLoader.superclass.constructor.call (this, config);
}
Ext.extend (Ext.tree.JsonPluginTreeLoader, Ext.tree.TreeLoader, {
Processresponse:function (response, N      Ode, callback) {
var json = Response.responsetext;
 try {
var o = Response.responsedata | | Ext.decode (JSON);
//Adds the following processing---------------------
if (Ext.type (o) = = ' object ') {//If the object is returned to get his root part, Rootname can be used 
O = o[this.rootname to configure | | ' Root '];       
}
//--------------------------------------------------
Node.beginupdate ();
         for (var i = 0, len = o.length i < len; i++) {
var n = this.createnode (o[i]);
         if (n) {
Node.appendchild (n);
      
}
Node.endupdate ();
This.runcallback (cAllback, Scope | | node, [node]);     
} catch (e) {
This.handlefailure (response);
}
}
);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.