简体   繁体   English

如何计算Javascript Fancytree上的子节点数?

[英]How to Count Children Nodes on Javascript Fancytree?

I created a Category tree using Fancytree with Drag & Drop Functionality like 我使用带有拖放功能的Fancytree创建了一个类别树,例如

在此处输入图片说明

Now, I want to set limit for child node. 现在,我想为子节点设置限制。 if parent node already have 3 child node then his not able to create new child not for example 如果父节点已经有3个子节点,那么他就无法创建新的子节点,例如

Category 类别

parent category 父类别

  • child category Allowed 子类别允许

    • Child Category Allowed 允许的子类别

      • Child Category Not Allowed to Move 子类别不允许移动

like this so i create javascript for this. 像这样,所以我为此创建了javascript。

dragDrop: function(node, data) {
if( node.getLevel() >= 3 ){
    return false;
}
console.log( node );
console.log( data );
var parentNodeKey = node.key;
var sourceNode = $(data.helper).data("ftSourceNode");
if( !data.otherNode ){
    var title = $(data.draggable.element).text() + " (" + (count)++ + ")";
    node.addNode({title: title}, data.hitMode);
    return;
}
data.otherNode.moveTo(node, data.hitMode);

} }

This is working fine when i move any single category. 当我移动任何单个类别时,这工作正常。 but this is not working when i move "Moved Node" category because this category already have a 2 child node and that child node already have 2 child nodes like 但这在我移动“已移动节点”类别时不起作用,因为该类别已经有2个子节点,并且该子节点已经具有2个子节点,例如

在此处输入图片说明

I move the "Moved Node" and this is Working how can i count that child nodes or stop to moved that nodes. 我移动了“已移动节点”,这正在工作,我如何计算该子节点或停止移动该节点。 i want to set limit for creating 3 child nodes. 我想为创建3个子节点设置限制。 How can i do this. 我怎样才能做到这一点。 and how can i count the all child nodes of moveing category. 以及如何计算移动类别的所有子节点。

Thanks 谢谢

Child nodes can be counted using node.countChildren , but from your description I guess you want to count the maximum level of child nodes? 可以使用node.countChildren来计数子节点,但是根据您的描述,我想您要计算子节点的最大级别

There is no builtin method for that, but you can implement it using node.visit() . 没有内置方法,但是您可以使用node.visit()实现它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM