easyui tree

<h2>Basic Tree</h2>
	<p>Click the arrow on the left to expand or collapse nodes.</p>
	<div style="margin:20px 0;"></div>
	<div class="easyui-panel" style="padding:5px">
		<ul class="easyui-tree">
			<li>
				<span>My Documents</span>
				<ul>
					<li data-options="state:'closed'">
						<span>Photos</span>
						<ul>
							<li>
								<span>Friend</span>
							</li>
							<li>
								<span>Wife</span>
							</li>
							<li>
								<span>Company</span>
							</li>
						</ul>
					</li>
					<li>
						<span>Program Files</span>
						<ul>
							<li>Intel</li>
							<li>Java</li>
							<li>Microsoft Office</li>
							<li>Games</li>
						</ul>
					</li>
					<li>index.html</li>
					<li>about.html</li>
					<li>welcome.html</li>
				</ul>
			</li>
		</ul>
	</div>

		<ul id="regionTree"></ul>
<script>
$('#regionTree').tree({
           cascadeCheck: false,
            //onlyLeafCheck: true,
            checkbox: true,
            data: [{
                "id": 1,
                "text": "第一",
                "state": "closed",
                    "children": [{
                        "id": 111,
                        "text": "Friend"
                    }, {
                        "id": 112,
                        "text": "Wife"
                    }, {
                        "id": 113,
                        "text": "Company"
                    }]
                }, {
                    "id": 12,
                    "text": "Program Files",
                    "state": "closed",
                    "children": [{
                        "id": 121,
                        "text": "Intel"
                    }, {
                        "id": 122,
                        "text": "Java",
                        "attributes": {
                            "p1": "Custom Attribute1",
                            "p2": "Custom Attribute2"
                        }
                    }, {
                        "id": 123,
                        "text": "Microsoft Office"
                    }, {
                        "id": 124,
                        "text": "Games"
                       
                    }]
                }, {
                    "id": 13,
                    "text": "index.html"
                }, {
                    "id": 14,
                    "text": "about.html"
                }, {
                    "id": 15,
                    "text": "汉字啊1.html"
                },{
                    "id": 16,
                    "text": "汉字啊",
                    "state": "closed",
                    "children": [{
                        "id": 161,
                        "text": "Intel"
                    }, {
                        "id": 162,
                        "text": "什么",
                        "attributes": {
                            "p1": "什么1",
                            "p2": "神2"
                        }
                    }, {
                        "id": 163,
                        "text": "捕"
                    }, {
                        "id": 164,
                        "text": "未完"
                    }]
                }]
            ,
            width: 160,
            height: 32,
            panelHeight: 400,
            animate:true,   
            lines:true,    
            onlyLeafCheck: true,//只选叶子节点
           
            onLoadSuccess:function(node,data){
            	 $('#regionTree').tree("collapseAll")
            },
            onSelect: function (node) {
                var cknodes = $('#regionTree').tree("getChecked");
                for (var i = 0; i < cknodes.length; i++) {
                    if (cknodes[i].id != node.id) {
                        $('#regionTree').tree("uncheck", cknodes[i].target);
                    }
                }
                if (node.checked) {
                    $('#regionTree').tree('uncheck', node.target);

                } else {
                    $('#regionTree').tree('check', node.target);

                }

            },
            onCheck: function (node, checked) {
                $(this).find('span.tree-checkbox').unbind().click(function () {
                    $('#regionTree').tree('select', $(this).parent());
                    return false;
                });
            }
        })
发布了42 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/wzwzwz555/article/details/88399778