Implement the dhtmlxtree tree control click expand and contract function

Source: Internet
Author: User

Dhtmlxtree is a pretty good JavaScript tree control, which is used by the Web Background Management System to display functional menus or institutions, such as hierarchical and subordinate relationships, you can also customize icons and provide a wide range of APIs. For more information, see dhtmlxtree help documentation.

The effect is as follows:

By default, the dhtmlxtree tree control uses double-click mouse to expand the nodes to which it belongs. In fact, this is not in line with the usage habits of most people. It is better to expand and contract nodes by clicking, it is not difficult to implement this function. The key is to listen to the onclick event. The specific implementation is as follows:

 Tree  =     New  Dhtmlxtreeobject (  "  Treeboxbox_tree  "  ,  "  100% "  ,  "  100%  "  ,  0  );
Tree. setimagepath (
" Tree/ " );
Tree. loadxmlstring (xmltree)
Tree. attachevent (
" Onclick " , Function (ID ){
VaR Hrefurl = Tree. getuserdata (ID, " URL " );
// Click expand and contract
// VaR Itemid = tree. getselecteditemid ();
VaR Itemid = ID;

If (Tree. haschildren (Itemid )){
If (Tree. getopenstate (Itemid) = " 1 " ){
Tree. closeitem (Itemid)
}
Else {
Tree. openitem (Itemid)
}
}
});

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.