JS code: Get the tree data in Ajax way
$ ('. Page-content-area '). Ace_ajax (' loadscripts ', scripts, function () {
JQuery (function ($) {
var sampleData = Initiatedemodata (); $ ("#tree1"). Ace_tree ({
datasource:sampledata[' DataSource1 '),
Multiselect:false,
Folderselect:false,
Cacheitems:true,
' Open-icon ': ' Ace-icon tree-minus ',///
' Close-icon ': ' Ace-icon tree-plus ',
' Selectable ': true,
' Selected-icon ': ' Ace-icon fa Fa-check ',
' Unselected-icon ': ' Ace-icon fa fa-times ',
loadinghtml: ' <div class= "tree-loading" ><i class= "Ace-icon fa fa-refresh fa-spin Blue" ></i></div > '
}). On (' Selected.fu.tree ', function (e) {
}). On (' Loaded.fu.tree ', function (e) {
}). On (' Deselected.fu.tree ', function (e) {
});
function Initiatedemodata () {
var tree_data;
$.ajax ({
URL: "",/////////ajax gets the URL address of the data
Type: "Get",
Async:false,
Success:function (data) {
Tree_data = eval ("(" +data+ ")");
},
Error:function (data) {
}
});
var DataSource1 = function (options, callback) {
var $data = null
if (! (" Text "in Options"
&&! ("type" in Options)) {
$data = tree_data;//the Root tree
Callback ({
Data: $data
});
Return
} else if ("type" in Options
&& Options.type = = "folder") {
if ("AdditionalParameters" in Options
&& "Children" in Options.additionalparameters)
$data = Options.additionalParameters.children
|| {};
Else
$data = {}//no data
}
if ($data! = null)//this setTimeout is only for mimicking some random delay
SetTimeout (function () {
Callback ({
Data: $data
});
}, 200);
}
return {' DataSource1 ':d AtaSource1};
}
})
});
Gets the ID and name of the selected data in the tree
function Getdatas () {
var output = "";
var ids = "";
var items = $ (' #tree1 '). Tree (' SelectedItems ');
for (var i in items) if (Items.hasownproperty (i)) {
var item = Items[i];
ids + = item.additionalparameters[' id ' + ",";
Output + = Item.text + ",";
}
ids = ids.substring (0, Ids.lastindexof (","));
Output = output.substring (0, Output.lastindexof (","));
Alert (ids+ "___" +output);
}
The format of the data obtained in the background:
Tree data, basically only the text and type two properties, the other required properties need to be added to AdditionalParameters, such as: id,children,item-selected
Text: Make a display of the contents of the tree, Type:folder and item two. The folder representation is collapsible and has child nodes. The item represents a node that has no child nodes.
AdditionalParameters This property is used to supplement other properties of the tree
Children:folder the attributes that need to be added to the node, all of its child nodes need to be placed inside the children
Item-selected: This property is automatically selected in the page
It's also the stupidest way to put this data together, and it's best to use object-oriented thinking to define these as objects.
{' Criminal investigation ': {text: ' Criminal investigation ', type: ' Folder ', ' AdditionalParameters ': {id: ' 1 ', ' children ': {' trace Test ': {text: ' Trace Test ', type: ' Item ', ' AdditionalParameters ': {ID: ' 10 '}, ' forensic light ': {text: ' Forensic Light ', type: ' Item ', ' AdditionalParameters ': {ID: ' 11 '}}, ' site survey ': { Text: ' Site survey ', type: ' Item ', ' AdditionalParameters ': {ID: ' 12 '}, ' anti-terrorism department ': {text: ' Anti-Terrorism department ', type: ' Item ', ' AdditionalParameters ': {id: ' 13 '}, ' Audio-visual technology ': {text: ' Audio-visual technology ', type: ' Item ', ' AdditionalParameters ': {ID: ' 9 ', ' Item-selected ': True}}}},
' Technology ': {text: ' Technology ', type: ' Folder ', ' AdditionalParameters ': {id: ' ' ', ' children ': {' listen ': {text: ' Listen ', type: ' Item ', ' AdditionalParameters ': {id: ' 20 '}, ' locate ': {text: ' Location ', type: ' Item ', ' AdditionalParameters ': {id: ' 21 '}}}},
' Network Supervisor ': {text: ' Network Monitor ', type: ' Folder ', ' AdditionalParameters ': {id: ' ' + ', ' children ': {' Internet public opinion ': {text: ' Internet public opinion ', type: ' Item ', ' AdditionalParameters ': {id: ' 26 '}, ' Public Information Network monitoring ': {text: ' Public Information Network monitoring ', type: ' Item ', ' AdditionalParameters ': {ID: ' 27 '}}}},
' Traffic police ': {text: ' Police ', type: ' Folder ', ' AdditionalParameters ': {ID: ' + ', ' children ': {' accident ': {text: ' Traffic accident ', type: ' Item ', ' AdditionalParameters ': {id: ' 33 '}, ' Traffic management ': {text: ' Traffic reason Management ', type: ' Item ', ' AdditionalParameters ': {id: ' 34 '}}}}}
Background code
map<string, string> param = new hashmap<string, string> ();
String isSelected = Request.getparameter ("Selectedids");
StringBuffer SBF = new StringBuffer (); Assembly data
Sbf.append ("{");
if (isSelected! = null &&!isselected.equals ("")) {/////This description is checked
string[] Selectedid = Isselected.split (";");
int selectedcounts = 0;
List typelist = Ptypeservice.getlist ();
for (int i = 0; i < typelist.size (); i + +) {
Ptype p = (Ptype) typelist.get (i);
Sbf.append ("'" +p.getname () + "': {text: '" +p.getname () + "', type: ' Folder ', ' AdditionalParameters ': {id: '" +p.getid () + "' ,");
Param.put ("pid", P.getid ());
list<ptype> childlist = Ptypeservice.getchildren (param);
if (Childlist.size () >0) {
Sbf.append ("' Children ': {");
for (int j= 0; J < Childlist.size (); j + +) {
Ptype TP = Childlist.get (j);
Sbf.append ("'" +tp.getname () + "'"). Append (": {text: '" +tp.getname () + "', type: ' Item ', ' AdditionalParameters ': {ID: '" + Tp.getid () + "'");
if (Selectedcounts < selectedid.length) {
for (int k = 0; k < selectedid.length; k++) {
if (Tp.getid (). Equals (Selectedid[k])) {
Sbf.append (", ' item-selected ': true");
Selectedcounts + +;
Break
}
}
}
Sbf.append ("}},");
}
String st = sbf.tostring ();
st = st.substring (0, St.length ()-1);
SBF = new StringBuffer ();
Sbf.append (ST);
Sbf.append ("}");
}
Sbf.append ("}");
Sbf.append ("},");
}
}else{
List typelist = Ptypeservice.getlist ();
for (int i = 0; i < typelist.size (); i + +) {
Ptype p = (Ptype) typelist.get (i);
Sbf.append ("'" +p.getname () + "': {text: '" +p.getname () + "', type: ' Folder ', ' AdditionalParameters ': {id: '" +p.getid () + "' ,");
Param.put ("pid", P.getid ());
list<ptype> childlist = Ptypeservice.getchildren (param);
if (Childlist.size () >0) {
Sbf.append ("' Children ': {");
for (int j= 0; J < Childlist.size (); j + +) {
Ptype TP = Childlist.get (j);
Sbf.append ("'" +tp.getname () + "'"). Append (": {text: '" +tp.getname () + "', type: ' Item ', ' AdditionalParameters ': {ID: '" + Tp.getid () + "'}},");
}
String st = sbf.tostring ();
st = st.substring (0, St.length ()-1);
SBF = new StringBuffer ();
Sbf.append (ST);
Sbf.append ("}");
}
Sbf.append ("}");
Sbf.append ("},");
}
}
String str = sbf.tostring ();
str = str.substring (0,str.length ()-1);
str + = "}";
Writer out = Response.getwriter ();
Out.write (str);