Ztree tree-shaped components combined with the use of bootstrap

Source: Internet
Author: User

Ztree parameter settings

var setting = {              view: {                false  //Hide icon            },            data: {                key: {                    "Setsubarea"  //JSON set the name of the child node JSON format {ID: ' 1 ', Name: ' Shenzhen ', setsubarea[{}]}}            ,            check: {                true,                false,                "Y": "P", "N": "S" }                }               // whether a CheckBox  is displayed on each node        ;  

Request to load data

1$ (document). Ready (function(){2             //loading a page is sending an asynchronous request3 $.ajax ({4Type: ' POST ',   5DataType: "JSON",   6URL: "Queryareatreejson.action",//the requested action path7Successfunction(data) {//The request succeeds after processing the function. 8Znodes =data;9Ztreeobj= $.fn.ztree.init ($ ("#areaTree"), setting, data);
Depending on the value in input, the corresponding node is selected in the tree structureTen varTreeobj = $.fn.ztree.getztreeobj ("Areatree"); One varInputarea = $ ("#areaNames"). Val (). split (); A for(vari = 0; i < inputarea.length; i + +) { - varnode = Treeobj.getnodebyparam ("name", Inputarea[i]);//$ ("#areaNames"). Val () -Treeobj.checknode (node,true,true); the } - } - }); -$ ("#area"). blur (Getselectnodes); Input get focus Auto trigger +});

Based on the value selected by Ztree, displayed in the input box

functiongetselectnodes () {varTreeobj = $.fn.ztree.getztreeobj ("Areatree"); varnodes = Treeobj.getcheckednodes (true); varAreaarr = [];  for(vari = 0; i < nodes.length; i + +){            varnode =Nodes[i];            Console.log (node); if(Node.isparent = =false|| (Node.check_child_state = = 0) {//Selected node and the child node of the node is not selected or is a leaf node areaarr.push (node.name); }        }                 $("#areaNames"). Val (Areaarr.join (",")); $(' #myModal '). Modal (' Hide '); }
<Buttonclass= "btn btn-primary btn-xs"Data-toggle= "Modal"Data-target= "#myModal"onclick= "return false;">Select Region</Button><!--modal frame (Modal) -        <Divclass= "Modal Fade"ID= "Mymodal"TabIndex= "-1"role= "Dialog"Aria-labelledby= "Mymodallabel"Aria-hidden= "true">           <Divclass= "Modal-dialog">              <Divclass= "Modal-content">                 <Divclass= "Modal-header"style= "padding:5px;">                    <!--<button type= "button" class= "btn Btn-xs" data-dismiss= "modal" aria-hidden= "true" >                    &times; </button> -                    <h4class= "Modal-title"ID= "Mymodallabel">Select Region</h4>                 </Div>                 <Divclass= "Modal-body">                    <Divclass= "Ztreedemobackground Left">                        <ulID= "Areatree"class= "Ztree"style= "Max-height:300px;width:auto; overflow-y:scroll;"></ul>                    </Div>                 </Div>                 <Divclass= "Modal-footer"style= "padding:5px;">                    <Buttontype= "button"class= "Btn btn-primary"onclick= "getselectnodes ();">Confirm</Button>                    <Buttontype= "button"class= "Btn Btn-default"Data-dismiss= "Modal"onclick= "getselectnodes ();">Close</Button>                 </Div>              </Div><!--/.modal-content -            </Div><!--/.modal -        </Div>

Ztree tree-shaped components combined with the use of bootstrap

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.