js中如何从函数中实现页面转换?
在树形结构中,想要根据结点进行页面转化
在setting的callback中定义了onClick函数
然后如何根据点击进行页面跳转呢?
主要就是onclick函数要怎么写?
function onclick(event, treeId, treeNode) {
alert('页面转换');
console.log(treeNode.id);
//根据treeNode.id 进行页面跳转,当值为1时 跳转到htmla.html页面中
if(treeNode.id == 1){
}
}
<SCRIPT type="text/javascript">
<!--
var setting = {
view: {
addHoverDom: addHoverDom,
removeHoverDom: removeHoverDom,
selectedMulti: false
},
edit: {
enable: true,
editNameSelectAll: true,
},
data: {
simpleData: {
enable: true
}
},
callback: {
beforeDrag: beforeDrag,
beforeEditName: beforeEditName,
beforeRemove: beforeRemove,
beforeRename: beforeRename,
onRemove: onRemove,
onRename: onRename,
onClick: onclick
}
};
var zNodes = [{
id: 1,
pId: 0,
name: "卫星/平台",
open: true
},
];
var log, className = "dark";
//点击事件
function onclick(event, treeId, treeNode) {
alert('页面转换');
console.log(treeNode.id);
//根据treeNode.id 进行页面跳转,当值为1时 跳转到htmla.html页面中
if(treeNode.id == 1){
}
}
//禁止拖拽
function beforeDrag(treeId, treeNodes) {
return false;
}
//用于捕获节点编辑按钮的 click 事件,并且根据返回值确定是否允许进入名称编辑状态
function beforeEditName(treeId, treeNode) {
className = (className === "dark" ? "" : "dark");
showLog("[ " + getTime() + " beforeEditName ] " + treeNode.name);
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.selectNode(treeNode);
setTimeout(function() {
if (confirm("进入节点 -- " + treeNode.name + " 的编辑状态吗?")) {
setTimeout(function() {
zTree.editName(treeNode);
}, 0);
}
}, 0);
return false;
}
//用于捕获节点被删除之前的事件回调函数
function beforeRemove(treeId, treeNode) {
className = (className === "dark" ? "" : "dark");
showLog("[ " + getTime() + " beforeRemove ] " + treeNode.name);
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.selectNode(treeNode);
return confirm("确认删除 节点 -- " + treeNode.name + " 吗?");
}
//用于捕获删除节点之后的事件回调函数
function onRemove(e, treeId, treeNode) {
showLog("[ " + getTime() + " onRemove ] " + treeNode.name);
}
//用于捕获节点编辑名称结束(Input 失去焦点 或 按下 Enter 键)之后,更新节点名称数据之前的事件回调函数,并且根据返回值确定是否允许更改名称的操作
function beforeRename(treeId, treeNode, newName, isCancel) {
className = (className === "dark" ? "" : "dark");
showLog((isCancel ? "<span style='color:red'>" : "") + "[ " + getTime() +
" beforeRename ] " + treeNode.name + (isCancel ? "</span>" : ""));
if (newName.length == 0) {
setTimeout(function() {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.cancelEditName();
alert("节点名称不能为空.");
}, 0);
return false;
}
return true;
}
//用于捕获节点编辑名称结束之后的事件回调函数。
function onRename(e, treeId, treeNode, isCancel) {
showLog((isCancel ? "<span style='color:red'>" : "") + "[ " + getTime() + " onRename ] " +
treeNode.name + (isCancel ? "</span>" : ""));
}
function showLog(str) {
if (!log) log = $("#log");
log.append("<li class='" + className + "'>" + str + "</li>");
if (log.children("li").length > 8) {
log.get(0).removeChild(log.children("li")[0]);
}
}
function getTime() {
var now = new Date(),
h = now.getHours(),
m = now.getMinutes(),
s = now.getSeconds(),
ms = now.getMilliseconds();
return (h + ":" + m + ":" + s + " " + ms);
}
var newCountxj = 1;
var newCountpt = 1;
function addHoverDom(treeId, treeNode) {
var sObj = $("#" + treeNode.tId + "_span");
if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
if (treeNode.level == 0) {
var addStr = "<span class='button add' id='addBtn_" + treeNode.tId +
"' title='添加相机' onfocus='this.blur();'></span>";
sObj.after(addStr);
var btn = $("#addBtn_" + treeNode.tId);
if (btn) btn.bind("click", function() {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
if (treeNode.level == 0) {
zTree.addNodes(treeNode, {
id: (100 + newCountxj),
pId: treeNode.id,
name: "相机" + (newCountxj++),
});
} else {
zTree.addNodes(treeNode, {
id: (200 + newCountpt),
pId: treeNode.id,
name: "激光平台" + (newCountpt++)
});
}
return false;
});
} else {
var addStr = "<span class='button add' id='addBtn_" + treeNode.tId +
"' title='添加光学系统' onfocus='this.blur();'></span>";
sObj.after(addStr);
var btn = $("#addBtn_" + treeNode.tId);
if (btn) btn.bind("click", function() {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
if (treeNode.level == 0) {
zTree.addNodes(treeNode, {
id: (100 + newCountxj),
pId: treeNode.id,
name: "相机" + (newCountxj++),
});
} else {
zTree.addNodes(treeNode, {
id: (200 + newCountpt),
pId: treeNode.id,
name: "激光平台" + (newCountpt++)
});
}
return false;
});
}
};
function removeHoverDom(treeId, treeNode) {
$("#addBtn_" + treeNode.tId).unbind().remove();
};
function selectAll() {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.setting.edit.editNameSelectAll = $("#selectAll").attr("checked");
}
$(document).ready(function() {
//创建tree的方法
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
$("#selectAll").bind("click", selectAll);
});
//-->
</SCRIPT>