我需要从客户端的ASP.NET Treeview知道所选节点的深度。
反正知道这个吗?
谢谢!
答案 0 :(得分:1)
不是我喜欢这样做,如果时间允许,我会尝试找另一种方法;
var id = TreeView2_Data.selectedNodeID.value; //Get the Selectednode id of tv with asp.net id of TreeView2
if (id.length > 0) {
var selectedNode = document.getElementById(id); //Get the Selectnode object -> selectedNode.innerText will give you the text of the node
if ((typeof (selectedNode) != "undefined") && (selectedNode != null)) {
//Determine the depth of the select node
var nodeDepth = selectedNode.host.split('\\\\').length // the separator is the default single \. Tv adds the extra on and of course we have to add 2 for the string literals.
//node depth wil always be one more than the real node depth, so root is one.
if (nodeDepth >= 4) {
//Do stuff or return value
}
}
}
希望它有所帮助。如果您找到替代方案,请回发。