ztree——修改setting配置

var setting = {
	view: {
		selectedMulti: false
	},
	check: {
		enable: true,
		chkStyle: "checkbox",
		chkboxType: { "Y": "s", "N": "ps" }
	},
	data: {
		simpleData: {
			enable: true
		}
	},
	callback: {
		beforeCheck: zTreeBeforeCheck,
		onCheck: zTreeOnCheck,
		onRightClick: onRightClick
	}
};

假如要修改setting配置中得chkboxType,若直接操控setting修改是无效得
错误操作:

setting.check.chkboxType={ "Y": "", "N": "" }

正确操作方法:

let treeObj = $.fn.zTree.getZTreeObj("treeDemo");
treeObj.setting.check.chkboxType = { "Y" : "", "N" : "" };
<!DOCTYPE html> <HTML> <HEAD> <TITLE> ZTREE DEMO - checkbox</TITLE> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="zTreeStyle.css" type="text/css"> <script type="text/javascript" src="jquery-1.4.4.min.js"></script> <script type="text/javascript" src="jquery.ztree.core.js"></script> <script type="text/javascript" src="jquery.ztree.excheck.js"></script> <SCRIPT type="text/javascript"> var setting = {check: {enable: true},data: {simpleData: {enable: true}}}; var zNodes =[ { id:1, pId:0, name:"全选", open:true}, { id:11, pId:1, name:"报表", open:true}, { id:111, pId:11, name:"报表管理",open:true}, { id:112, pId:11, name:"报表概况",open:true}, { id:12, pId:1, name:"我的", open:true}, { id:121, pId:12, name:"修改密码",open:true}, { id:122, pId:12, name:"意见反馈",open:true} ]; $(document).ready(function(){ $.fn.zTree.init($("#treeDemo"), setting, zNodes); var zTree = $.fn.zTree.getZTreeObj("treeDemo"), type = { "Y":'ps', "N":'ps'}; zTree.setting.check.chkboxType = type; }); function aa(){ var treeObj=$.fn.zTree.getZTreeObj("treeDemo"); nodes=treeObj.getCheckedNodes(true); var nodes1 = treeObj.getNodes(); var aa1= treeObj.transformToArray(nodes1); for(var i=0; i < aa1.length;i++){ var node = treeObj.getNodeByParam("id",aa1[i].id ); treeObj.checkNode(node,true,true); treeObj.updateNode(node); } } </SCRIPT> </HEAD> <BODY> <div class="content_wrap"> <div class="zTreeDemoBackground left"> <ul id="treeDemo" class="ztree"></ul> </div> <button value="dianji" onclick="aa()" /> </div> </BODY> </HTML>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值