Angularjs Treeview - 移动节点

时间:2014-08-05 13:24:29

标签: javascript jquery angularjs treeview

我对angular很新,并使用以下示例创建了一个树视图: jsfiddle.net/eu81273/8LWUc/18 /

这是我使用的数据结构:

treeview1 = [
                {
                    roleName: "User2", roleId: "role2", type: "region", "children": [
                    { roleName: "subUser2", roleId: "role21", collapsed: false, type: "branch", children: [] },
                    {
                        roleName: "subUser21", roleId: "role22", collapsed: false, type: "divison", children: [
                        {
                            roleName: "subUser2-1", roleId: "role211", type: "branch", children: [
                            { roleName: "subUser2-1-1", roleId: "role2211", type: "branch", children: [] },
                            { roleName: "subUser2-1-2", roleId: "role2212", type: "branch", children: [] }
                            ]
                        }
                        ]
                    }
                    ]
                },

                {
                    roleName: "User3", roleId: "role3", children: [
                    { roleName: "subUser3", roleId: "role31", collapsed: false, children: [] },
                    {
                        roleName: "subUser31", roleId: "role32", children: [
                        {
                            roleName: "subUser3-1", roleId: "role3121", "children": [
                            { roleName: "subUser3-1-1", roleId: "role3221", children: [] },
                            { roleName: "subUser3-1-2", roleId: "role3222", children: [] }
                            ]
                        }
                        ]
                    }
                    ]
                },

                {
                    roleName: "User4", roleId: "role4", children: [
                    { roleName: "subUser4", roleId: "role41", children: [] },
                    {
                        roleName: "subUser41", roleId: "role42", collapsed: false, "children": [
                        {
                            roleName: "subUser4-1", roleId: "role431", children: [
                            { roleName: "subUser4-1-1", roleId: "role4231", children: [] },
                            { roleName: "subUser4-1-2", roleId: "role4232", children: [] }
                            ]
                        }
                        ]
                    }
                    ]
                }
        ];

我现在树视图下方有两个按钮,上移和下移。 如果我选择一个叶节点并单击“向上”,它应该移动到上一个可用的父节点。如果我点击它,它应该移动到下一个可用的父级。

我尝试将其从树中删除并将其添加到节点但没有成功。 有人可以帮我这个吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

我检查了所有可能性,并根据深入分析,这是不可行的。

唯一可以做的是在下面的代码的帮助下选择当前节点(选定)的子节点:

$scope.nextNode = function () {
    $scope.tree01.selectNodeHead($scope.tree01.currentNode.children[0]);
    $scope.tree01.selectNodeLabel($scope.tree01.currentNode.children[0]);
};

此处nextNode是点击Next按钮时的函数调用。