哪里可以找到Javascript Tree Creator?

时间:2010-05-07 06:12:12

标签: javascript tree

你知道任何Javascript Tree Creator可以添加或删除最多3级的节点吗?

我目前正在使用jQuery树视图,但目前正在编写添加和删除很难的节点项。

干杯, 标记

3 个答案:

答案 0 :(得分:0)

检查我的jtree,它有一个非常好用且简单的api,有一些编辑例子

答案 1 :(得分:0)

尝试这个

http://kazge.com/show/zkjs/src/tree.html

它支持复选框,以及更多功能

项目的主页为https://code.google.com/p/zkjs/

答案 2 :(得分:0)

这是一个动作脚本版本,它像JS一样升级,除了JS中的行渲染器/画布不同。它将引导您访问更多脚本,因为tehre是一个在网上某处充满了此代码翻译的页面:

这段代码实际上是一个页面中某些代码的端口 http://rosettacode.org/wiki/Fractal_tree

[代码]

/*


  3D Fractal Tree

*/


    public var depth = 9;
    public var  angleSpread = 21.0;
    public var skew = 21.0;
    public var  branchMat : Material;
    public var  averaged = false;
    private var  deg_to_rad = 3.14159265 / 180.0;
    private var  scale = 0.50;
    private var  line : LineRenderer;
    private var  fractalTree : GameObject;
    private var  branch : GameObject;

    function Start () {
        //un-comment the line below to build the tree on start if not using MainController
        buildNewTree();
    }

    function killOldTree(){
        Destroy(fractalTree);   
    }

    function buildNewTree(){
        //Create a new empty gameObject to store our fractal tree
        fractalTree = new GameObject ("Fractal_Tree");
        fractalTree.transform.parent = gameObject.transform;
        if(averaged){angleSpread*=2;}
        drawTree(0.0, 0.0, 0.0, 0.0, 90.0, 90.0, depth);    
    }

    //A recursive function used to draw the fractal tree
    function drawTree( x1 : float,  y1 : float,  z1 : float,  y3 : float,  angle : float,  angle2 : float,  depth : int){
        if (depth != 0){
            //Set the x2 point
             var  x2  : float= x1 + (Mathf.Cos(angle * deg_to_rad) * depth * scale);

            //Set the z2 point
            var   z2  : float= z1 + (Mathf.Cos(angle2 * deg_to_rad) * depth * scale);

            //Set the y2 point
             var  y2  : float= y1 + (Mathf.Sin(angle * deg_to_rad) * depth * scale);

            //Set the y4 point
             var  y4  : float= y3 + (Mathf.Sin(angle2 * deg_to_rad) * depth * scale);

            //Average the y values
             var  n1 : float = (y3+y1)/2;
             var  n2  : float= (y4+y2)/2;

            //Call the drawline function, provide the coordinate data
            drawLine(x1, n1, z1, x2, n2, z2, depth);

            //Iterate the function recursively, change the rotation of the branches
            if(!averaged){
                if(depth % 2 == 0 ){
                    drawTree(x2, y2, z2, y4, angle - angleSpread - skew, angle2 - angleSpread- skew, depth - 1);
                    drawTree(x2, y2, z2, y4, angle + angleSpread - skew, angle2 + angleSpread- skew, depth - 1);
                }
                if(depth % 2 == 1 ){
                    drawTree(x2, y2, z2, y4, angle + angleSpread - skew, angle2-angleSpread- skew, depth - 1);
                    drawTree(x2, y2, z2, y4, angle - angleSpread - skew, angle2+angleSpread- skew, depth - 1);
                }
            }

            //Iterate the function recursively, change the rotation of the branches (rounded version)
            if(averaged){
                if(depth % 2 == 0 ){
                    drawTree(x2, y2, z2, y4, angle - angleSpread - skew, angle2 - skew, depth - 1);
                    drawTree(x2, y2, z2, y4, angle + angleSpread - skew, angle2 - skew, depth - 1);
                }
                if(depth % 2 == 1 ){                    
                    drawTree(x2, y2, z2, y4, angle - skew, angle2 - angleSpread - skew, depth  - 1);
                    drawTree(x2, y2, z2, y4, angle - skew, angle2 + angleSpread - skew, depth - 1);
                }
            }
        }
    }

    //Draws a single branch of the tree
    function drawLine(x1 : float,  y1 : float,  z1 : float,  x2 : float,  y2 : float,  z2 : float,  color : int){

        //Create a gameObject for the branch
        branch = new GameObject ("branch");

        //Make the branch child of the main gameobject
        branch.transform.parent = fractalTree.transform;

        //Add a line renderer to the branch gameobject
        line = branch.AddComponent("LineRenderer") ;//as LineRenderer;

        //Change the material of the LineRenderer
        line.material = branchMat;

        //Thin the branches through each iteration
        line.SetWidth(color*0.04, color*0.02);

        //Draw the line.
        line.SetPosition(0, new Vector3(x1,y1,z1));
        line.SetPosition(1, new Vector3(x2,y2,z2));
    }
[/code]