提交 fd4686dd 编写于 作者: Z ztree

* 【修改】addNodes 新方法 导致 拖拽节点时报错

   * 【增加】treeNode.getIndex 方法,可以快速获取 节点在 子节点中的位置
   * 【增加】treeNode.getPath 方法,可以快速获取 节点的所有父节点
上级 9912b29c
......@@ -196,8 +196,10 @@ var apiContent = {
{id:128, pId:1, t:"chkDisabled", name:"chkDisabled", iconSkin:"check", showAPI:true},
{id:127, pId:1, t:"click", name:"click", iconSkin:"core", showAPI:true},
{id:103, pId:1, t:"getCheckStatus", name:"getCheckStatus ()", iconSkin:"check", showAPI:true},
{id:135, pId:1, t:"getIndex", name:"getIndex ()", iconSkin:"core", showAPI:true},
{id:104, pId:1, t:"getNextNode", name:"getNextNode ()", iconSkin:"core", showAPI:true},
{id:105, pId:1, t:"getParentNode", name:"getParentNode ()", iconSkin:"core", showAPI:true},
{id:136, pId:1, t:"getPath", name:"getPath ()", iconSkin:"core", showAPI:true},
{id:106, pId:1, t:"getPreNode", name:"getPreNode ()", iconSkin:"core", showAPI:true},
{id:129, pId:1, t:"halfCheck", name:"halfCheck", iconSkin:"check", showAPI:true},
{id:107, pId:1, t:"icon", name:"icon", iconSkin:"core", showAPI:true},
......
此差异已折叠。
<div class="apiDetail">
<div>
<h2><span>Function()</span><span class="path">treeNode.</span>getIndex</h2>
<h3>概述<span class="h3_info">[ 依赖 <span class="highlight_green">jquery.ztree.core</span> 核心 js ]</span></h3>
<div class="desc">
<p></p>
<div class="longdesc">
<p>获取 treeNode 节点在同级节点中的位置。</p>
<p class="highlight_red">初始化节点数据时,由 zTree 增加此属性,请勿提前赋值</p>
</div>
</div>
<h3>Function 参数说明</h3>
<div class="desc">
<h4><b>返回值</b><span>Number</span></h4>
<p>treeNode 节点在同级节点中的位置。(从 0 开始)</p>
</div>
<h3>treeNode 举例</h3>
<h4>1. 获取当前被选中的节点在同级节点中的位置</h4>
<pre xmlns=""><code>var treeObj = $.fn.zTree.getZTreeObj("tree");
var sNodes = treeObj.getSelectedNodes();
if (sNodes.length > 0) {
var node = sNodes[0].getIndex();
}
</code></pre>
</div>
</div>
\ No newline at end of file
<div class="apiDetail">
<div>
<h2><span>Function()</span><span class="path">treeNode.</span>getPath</h2>
<h3>概述<span class="h3_info">[ 依赖 <span class="highlight_green">jquery.ztree.core</span> 核心 js ]</span></h3>
<div class="desc">
<p></p>
<div class="longdesc">
<p>获取 treeNode 节点的所有父节点(包括自己)。</p>
<p class="highlight_red">初始化节点数据时,由 zTree 增加此属性,请勿提前赋值</p>
</div>
</div>
<h3>Function 参数说明</h3>
<div class="desc">
<h4><b>返回值</b><span>Array (JSON)</span></h4>
<p> treeNode 节点的所有父节点的数据集合(包括自己)</p>
</div>
<h3>treeNode 举例</h3>
<h4>1. 获取当前被选中的节点的所有父节点</h4>
<pre xmlns=""><code>var treeObj = $.fn.zTree.getZTreeObj("tree");
var sNodes = treeObj.getSelectedNodes();
if (sNodes.length > 0) {
var node = sNodes[0].getPath();
}
</code></pre>
</div>
</div>
\ No newline at end of file
<div class="apiDetail">
<div>
<h2><span>Function()</span><span class="path">treeNode.</span>getIndex</h2>
<h3>Overview<span class="h3_info">[ depends on <span class="highlight_green">jquery.ztree.core</span> js ]</span></h3>
<div class="desc">
<p></p>
<div class="longdesc">
<p>Get the treeNode's index in its parent node's children.</p>
<p class="highlight_red">Do not initialize or modify it, it is created by the zTree.</p>
</div>
</div>
<h3>Function Parameter Descriptions</h3>
<div class="desc">
<h4><b>Return</b><span>Number</span></h4>
<p>the treeNode's index in its parent node's children. ( start at 0 )</p>
</div>
<h3>Examples of treeNode</h3>
<h4>1. Get the first selected node's index.</h4>
<pre xmlns=""><code>var treeObj = $.fn.zTree.getZTreeObj("tree");
var sNodes = treeObj.getSelectedNodes();
if (sNodes.length > 0) {
var node = sNodes[0].getIndex();
}
</code></pre>
</div>
</div>
\ No newline at end of file
<div class="apiDetail">
<div>
<h2><span>Function()</span><span class="path">treeNode.</span>getPath</h2>
<h3>Overview<span class="h3_info">[ depends on <span class="highlight_green">jquery.ztree.core</span> js ]</span></h3>
<div class="desc">
<p></p>
<div class="longdesc">
<p>Get the treeNode's all parent nodes. (Include itself)</p>
<p class="highlight_red">Do not initialize or modify it, it is created by the zTree.</p>
</div>
</div>
<h3>Function Parameter Descriptions</h3>
<div class="desc">
<h4><b>Return</b><span>Array (JSON)</span></h4>
<p>Array of treeNode's all parent nodes. (Include itself)</p>
</div>
<h3>Examples of treeNode</h3>
<h4>1. Get the first selected node's all parent nodes.</h4>
<pre xmlns=""><code>var treeObj = $.fn.zTree.getZTreeObj("tree");
var sNodes = treeObj.getSelectedNodes();
if (sNodes.length > 0) {
var node = sNodes[0].getPath();
}
</code></pre>
</div>
</div>
\ No newline at end of file
/*
* JQuery zTree core v3.5.19
* JQuery zTree core v3.5.19.1
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -9,7 +9,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2015-10-22
* Date: 2015-10-26
*/
(function($){
var settings = {}, roots = {}, caches = {},
......@@ -308,6 +308,8 @@
n.getParentNode = function() {return data.getNodeCache(setting, n.parentTId);};
n.getPreNode = function() {return data.getPreNode(setting, n);};
n.getNextNode = function() {return data.getNextNode(setting, n);};
n.getIndex = function() {return data.getNodeIndex(setting, n);};
n.getPath = function() {return data.getNodePath(setting, n);};
n.isAjaxing = false;
data.fixPIdKeyValue(setting, n);
},
......@@ -437,6 +439,17 @@
getCache: function(setting) {
return caches[setting.treeId];
},
getNodeIndex: function(setting, node) {
if (!node) return null;
var childKey = setting.data.key.children,
p = node.parentTId ? node.getParentNode() : data.getRoot(setting);
for (var i=0, l=p[childKey].length-1; i<=l; i++) {
if (p[childKey][i] === node) {
return i;
}
}
return -1;
},
getNextNode: function(setting, node) {
if (!node) return null;
var childKey = setting.data.key.children,
......@@ -469,6 +482,22 @@
var nameKey = setting.data.key.name;
return "" + node[nameKey];
},
getNodePath: function(setting, node) {
if (!node) return null;
var path;
if(node.parentTId) {
path = node.getParentNode().getPath();
} else {
path = [];
}
if (path) {
path.push(node);
}
return path;
},
getNodeTitle: function(setting, node) {
var t = setting.data.key.title === "" ? setting.data.key.name : setting.data.key.title;
return "" + node[t];
......@@ -1765,7 +1794,7 @@
consts = zt.consts;
})(jQuery);
/*
* JQuery zTree excheck v3.5.19
* JQuery zTree excheck v3.5.19.1
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -1774,7 +1803,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2015-10-22
* Date: 2015-10-26
*/
(function($){
//default consts of excheck
......@@ -2393,7 +2422,7 @@
}
})(jQuery);
/*
* JQuery zTree exedit v3.5.19
* JQuery zTree exedit v3.5.19.1
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -2402,7 +2431,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2015-10-22
* Date: 2015-10-26
*/
(function($){
//default consts of exedit
......@@ -2586,7 +2615,7 @@
}
if (moveType == consts.move.TYPE_INNER) {
function copyCallback() {
view.addNodes(_this.setting, targetNode, [newNode], isSilent);
view.addNodes(_this.setting, targetNode, -1, [newNode], isSilent);
}
if (tools.canAsync(this.setting, targetNode)) {
......@@ -2595,7 +2624,7 @@
copyCallback();
}
} else {
view.addNodes(this.setting, targetNode.parentNode, [newNode], isSilent);
view.addNodes(this.setting, targetNode.parentNode, -1, [newNode], isSilent);
view.moveNode(this.setting, targetNode, newNode, moveType, false, isSilent);
}
return newNode;
......@@ -3052,26 +3081,16 @@
}
}
if (moveType == consts.move.TYPE_INNER) {
view.addNodes(targetSetting, dragTargetNode, newNodes);
view.addNodes(targetSetting, dragTargetNode, -1, newNodes);
} else {
view.addNodes(targetSetting, dragTargetNode.getParentNode(), newNodes);
if (moveType == consts.move.TYPE_PREV) {
for (i=0, l=newNodes.length; i<l; i++) {
view.moveNode(targetSetting, dragTargetNode, newNodes[i], moveType, false);
}
} else {
for (i=-1, l=newNodes.length-1; i<l; l--) {
view.moveNode(targetSetting, dragTargetNode, newNodes[l], moveType, false);
}
}
view.addNodes(targetSetting, dragTargetNode.getParentNode(), moveType == consts.move.TYPE_PREV ? dragTargetNode.getIndex() : dragTargetNode.getIndex()+1, newNodes);
}
} else {
if (isCopy && moveType == consts.move.TYPE_INNER) {
view.addNodes(targetSetting, dragTargetNode, newNodes);
view.addNodes(targetSetting, dragTargetNode, -1, newNodes);
} else if (isCopy) {
view.addNodes(targetSetting, dragTargetNode.getParentNode(), moveType == consts.move.TYPE_PREV ? dragTargetNode.getIndex() : dragTargetNode.getIndex()+1, newNodes);
} else {
if (isCopy) {
view.addNodes(targetSetting, dragTargetNode.getParentNode(), newNodes);
}
if (moveType != consts.move.TYPE_NEXT) {
for (i=0, l=newNodes.length; i<l; i++) {
view.moveNode(targetSetting, dragTargetNode, newNodes[i], moveType, false);
......
此差异已折叠。
/*
* JQuery zTree core v3.5.19
* JQuery zTree core v3.5.19.1
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2015-10-22
* Date: 2015-10-26
*/
(function($){
var settings = {}, roots = {}, caches = {},
......@@ -307,6 +307,8 @@
n.getParentNode = function() {return data.getNodeCache(setting, n.parentTId);};
n.getPreNode = function() {return data.getPreNode(setting, n);};
n.getNextNode = function() {return data.getNextNode(setting, n);};
n.getIndex = function() {return data.getNodeIndex(setting, n);};
n.getPath = function() {return data.getNodePath(setting, n);};
n.isAjaxing = false;
data.fixPIdKeyValue(setting, n);
},
......@@ -436,6 +438,17 @@
getCache: function(setting) {
return caches[setting.treeId];
},
getNodeIndex: function(setting, node) {
if (!node) return null;
var childKey = setting.data.key.children,
p = node.parentTId ? node.getParentNode() : data.getRoot(setting);
for (var i=0, l=p[childKey].length-1; i<=l; i++) {
if (p[childKey][i] === node) {
return i;
}
}
return -1;
},
getNextNode: function(setting, node) {
if (!node) return null;
var childKey = setting.data.key.children,
......@@ -468,6 +481,22 @@
var nameKey = setting.data.key.name;
return "" + node[nameKey];
},
getNodePath: function(setting, node) {
if (!node) return null;
var path;
if(node.parentTId) {
path = node.getParentNode().getPath();
} else {
path = [];
}
if (path) {
path.push(node);
}
return path;
},
getNodeTitle: function(setting, node) {
var t = setting.data.key.title === "" ? setting.data.key.name : setting.data.key.title;
return "" + node[t];
......
此差异已折叠。
/*
* JQuery zTree excheck v3.5.19
* JQuery zTree excheck v3.5.19.1
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2015-10-22
* Date: 2015-10-26
*/
(function($){
//default consts of excheck
......
/*
* JQuery zTree excheck v3.5.19
* JQuery zTree excheck v3.5.19.1
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2015-10-22
* Date: 2015-10-26
*/
(function(m){var p,q,r,o={event:{CHECK:"ztree_check"},id:{CHECK:"_check"},checkbox:{STYLE:"checkbox",DEFAULT:"chk",DISABLED:"disable",FALSE:"false",TRUE:"true",FULL:"full",PART:"part",FOCUS:"focus"},radio:{STYLE:"radio",TYPE_ALL:"all",TYPE_LEVEL:"level"}},v={check:{enable:!1,autoCheckTrigger:!1,chkStyle:o.checkbox.STYLE,nocheckInherit:!1,chkDisabledInherit:!1,radioType:o.radio.TYPE_LEVEL,chkboxType:{Y:"ps",N:"ps"}},data:{key:{checked:"checked"}},callback:{beforeCheck:null,onCheck:null}};p=function(c,
a){if(a.chkDisabled===!0)return!1;var b=g.getSetting(c.data.treeId),d=b.data.key.checked;if(k.apply(b.callback.beforeCheck,[b.treeId,a],!0)==!1)return!0;a[d]=!a[d];e.checkNodeRelation(b,a);d=n(a,j.id.CHECK,b);e.setChkClass(b,d,a);e.repairParentChkClassWithSelf(b,a);b.treeObj.trigger(j.event.CHECK,[c,b.treeId,a]);return!0};q=function(c,a){if(a.chkDisabled===!0)return!1;var b=g.getSetting(c.data.treeId),d=n(a,j.id.CHECK,b);a.check_Focus=!0;e.setChkClass(b,d,a);return!0};r=function(c,a){if(a.chkDisabled===
......
/*
* JQuery zTree exedit v3.5.19
* JQuery zTree exedit v3.5.19.1
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2015-10-22
* Date: 2015-10-26
*/
(function($){
//default consts of exedit
......@@ -192,7 +192,7 @@
}
if (moveType == consts.move.TYPE_INNER) {
function copyCallback() {
view.addNodes(_this.setting, targetNode, [newNode], isSilent);
view.addNodes(_this.setting, targetNode, -1, [newNode], isSilent);
}
if (tools.canAsync(this.setting, targetNode)) {
......@@ -201,7 +201,7 @@
copyCallback();
}
} else {
view.addNodes(this.setting, targetNode.parentNode, [newNode], isSilent);
view.addNodes(this.setting, targetNode.parentNode, -1, [newNode], isSilent);
view.moveNode(this.setting, targetNode, newNode, moveType, false, isSilent);
}
return newNode;
......@@ -658,26 +658,16 @@
}
}
if (moveType == consts.move.TYPE_INNER) {
view.addNodes(targetSetting, dragTargetNode, newNodes);
view.addNodes(targetSetting, dragTargetNode, -1, newNodes);
} else {
view.addNodes(targetSetting, dragTargetNode.getParentNode(), newNodes);
if (moveType == consts.move.TYPE_PREV) {
for (i=0, l=newNodes.length; i<l; i++) {
view.moveNode(targetSetting, dragTargetNode, newNodes[i], moveType, false);
}
} else {
for (i=-1, l=newNodes.length-1; i<l; l--) {
view.moveNode(targetSetting, dragTargetNode, newNodes[l], moveType, false);
}
}
view.addNodes(targetSetting, dragTargetNode.getParentNode(), moveType == consts.move.TYPE_PREV ? dragTargetNode.getIndex() : dragTargetNode.getIndex()+1, newNodes);
}
} else {
if (isCopy && moveType == consts.move.TYPE_INNER) {
view.addNodes(targetSetting, dragTargetNode, newNodes);
view.addNodes(targetSetting, dragTargetNode, -1, newNodes);
} else if (isCopy) {
view.addNodes(targetSetting, dragTargetNode.getParentNode(), moveType == consts.move.TYPE_PREV ? dragTargetNode.getIndex() : dragTargetNode.getIndex()+1, newNodes);
} else {
if (isCopy) {
view.addNodes(targetSetting, dragTargetNode.getParentNode(), newNodes);
}
if (moveType != consts.move.TYPE_NEXT) {
for (i=0, l=newNodes.length; i<l; i++) {
view.moveNode(targetSetting, dragTargetNode, newNodes[i], moveType, false);
......
此差异已折叠。
/*
* JQuery zTree exHideNodes v3.5.19
* JQuery zTree exHideNodes v3.5.19.1
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2015-10-22
* Date: 2015-10-26
*/
(function($){
//default init node of exLib
......
/*
* JQuery zTree exHideNodes v3.5.19
* JQuery zTree exHideNodes v3.5.19.1
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2015-10-22
* Date: 2015-10-26
*/
(function(i){i.extend(!0,i.fn.zTree._z,{view:{clearOldFirstNode:function(c,a){for(var b=a.getNextNode();b;){if(b.isFirstNode){b.isFirstNode=!1;d.setNodeLineIcos(c,b);break}if(b.isLastNode)break;b=b.getNextNode()}},clearOldLastNode:function(c,a,b){for(a=a.getPreNode();a;){if(a.isLastNode){a.isLastNode=!1;b&&d.setNodeLineIcos(c,a);break}if(a.isFirstNode)break;a=a.getPreNode()}},makeDOMNodeMainBefore:function(c,a,b){c.push("<li ",b.isHidden?"style='display:none;' ":"","id='",b.tId,"' class='",l.className.LEVEL,
b.level,"' tabindex='0' hidefocus='true' treenode>")},showNode:function(c,a){a.isHidden=!1;f.initShowForExCheck(c,a);j(a,c).show()},showNodes:function(c,a,b){if(a&&a.length!=0){var e={},g,k;for(g=0,k=a.length;g<k;g++){var h=a[g];if(!e[h.parentTId]){var i=h.getParentNode();e[h.parentTId]=i===null?f.getRoot(c):h.getParentNode()}d.showNode(c,h,b)}for(var j in e)a=e[j][c.data.key.children],d.setFirstNodeForShow(c,a),d.setLastNodeForShow(c,a)}},hideNode:function(c,a){a.isHidden=!0;a.isFirstNode=!1;a.isLastNode=
......
......@@ -13,6 +13,11 @@
</font>
*2015.10.26* v3.5.19.1
* 【修改】addNodes 新方法 导致 拖拽节点时报错
* 【增加】treeNode.getIndex 方法,可以快速获取 节点在 子节点中的位置
* 【增加】treeNode.getPath 方法,可以快速获取 节点的所有父节点
*2015.10.22* v3.5.19
* 【修改】addNodes 方法支持直接添加新节点到任意位置 addNodes(parentNode, index, newNodes, isSilent)
* 【修改】selectstart 事件未解绑导致的内存泄漏
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册