Treepanel JSON Java background __js

Source: Internet
Author: User

function Createtreemenu () {//Create a panel of a tree


var treemenu = new Ext.tree.TreePanel ({
Lines:true,
minsize:150,
Border:false,
Root:new Ext.tree.AsyncTreeNode ({text: ' root '}),
Loader:new Ext.tree.TreeLoader ({dataurl: '/extdemo/getdata?action=treemenu '})
});

var win = new Ext.window ({
width:600,
height:400,
Items: [Treemenu]
});
Treemenu.expandall ();
Win.show ();
}

The dataurl corresponding servlet in loader invokes a method of generating JSON as follows:

Private String Gettreemenu () {
list<menu> list = new arraylist<menu> ();

for (int i = 0; i < 3; i++) {
Menu menu = new menu ();
Menu.seturl (NULL);
Menu.setid ("id_" + i);
Menu.settext ("menu" + i);
Menu.setleaf (FALSE);
for (int j = 0; J < 3; J + +) {
Menu submenu = new menu ();
Submenu.seturl ("/extdemo/getdata");
Submenu.setid (i + "" + j);
Submenu.settext ("Sub-menu" + j);
Submenu.setleaf (TRUE);
Menu.appendchild (submenu);
}
List.add (menu);
}

return Jsonarray.fromobject (list). ToString ();
}

The menu code in Gettreemenu is as follows:

public class Menu {

The names of the following fields must be this way because they correspond to the attributes of the TreeNode in ext.
Private String ID;
private String text;
Private String URL;
Private Boolean leaf;

Private list<menu> children = new arraylist<menu> ();


public void AppendChild (Menu submenu) {
This.children.add (submenu);
}

/** also has a lot of get and set methods

*/

}

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.