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);
}
}
);