ztree redio单选按钮

引用

<link href="~/Content/zTree_v3/metroStyle.css" rel="stylesheet" />
<script src="~/Scripts/zTree_v3/jquery.ztree.core.js"></script>
<script src="~/Scripts/zTree_v3/jquery.ztree.excheck.js"></script>  //带redio要引用的

 

js

<script>

  $(function () {
var setting = {

check: { enable: true, chkStyle: "radio", radioType: "level" },

data: { simpleData: { enable: true } },

callback: { onCheck: zTreeOnCheck }
};

//选择

function zTreeOnCheck(event, treeId, treeNode) {

alert(treeId + treeNode + "你成功了");

};

var zNodes = JSON.parse('@Html.Raw(ViewBag.SectorStructureTree)');

var code;

function setCheck() {
var type = $("#level").attr("checked") ? "level" : "all";
setting.check.radioType = type;
showCode('setting.check.radioType = "' + type + '";');
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
}


function showCode(str) {
if (!code) code = $("#code");
code.empty();
code.append("<li>" + str + "</li>");
}


$(document).ready(function () {
setCheck(); $("#level").bind("change", setCheck);
$("#all").bind("change", setCheck);
});


$("#okbtn").click(function () {
var node;
var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
nodes = treeObj.getCheckedNodes(true)
v = "";
if (nodes.length > 0) {
Node = nodes[0];
}

var v = Node.name;
var pid1 = Node.parentTId;
for (var i = 0; i < Node.level; i++)
{
var pidNode = treeObj.getNodeByTId(pid1);
pid1 = pidNode.parentTId;
v = pidNode.name + "》" + v;
}
alert(v);
})

})

</script>

html

 


<div>
<p>知识树Redio选择</p>


<div class="content_wrap" id="tree">

<div>

<ul id="treeDemo" class="ztree"></ul>

</div>

</div>

<input type="button" value="确定" id="okbtn" />

</div>

 

posted @ 2017-11-29 11:40  haifeng_0712  阅读(2746)  评论(0编辑  收藏  举报