如何在ui顶部添加新节点

在我的应用程序中,我使用了有角度的ui-tree。

现在添加我在下面的代码中使用的新节点

 <button class="btn btn-info btn-circle btn-sm" type="button" ng-click='x.tasks.push({task: "New Task",depth:"2", tasks:[]})' style="margin-top:15px" data-nodrag><i class="fa fa-plus"></i></button>

 <script type="text/ng-template" id="nodes_renderer.html">
                            <div ui-tree-handle class="tree-node tree-node-content">

                                <div style="width:100%">
                                    <div style="width:87%;display: inline-block">
                                        <a class="" style="color:#c1c1c1" data-nodrag ng-click="toggle(this)"><span class="fa" ng-class="{'fa-plus': collapsed, 'fa-minus': !collapsed}"></span>
                                            <span class="label label-info"><i class="fa fa-tasks"></i></span> </a>
                                            <span style="width:80%;word-wrap: break-word" class="remove-editable-click cursor-pointer" editable-text="node.task" buttons="no" e-ng-model="WBSData.task" e-ng-blur="changeFieldEdit(this)" e-required data-nodrag e-style="border:1px solid #DDDDDD;width:90px">
                                               {{node.task}}
                                            </span>
                                    </div>
                                    <div style="width:10%;display: inline-block">
                                        <input icheck type="checkbox" ng-model="node.WBSDataSelectedTask" checklist-value="node.task" style="float:right" value="none">
                                    </div>

                                </div>
                            </div>
                            <ol ui-tree-nodes="" ng-model="node.subtasks" ng-class="{hidden: collapsed}">
                                <li ng-repeat="node in node.subtasks" ui-tree-node ng-include="'nodes_renderer1.html'">
                                </li>
                            </ol>
                        </script>
                        <div ui-tree="treeOptions" id="tree-root">

                            <ol ui-tree-nodes ng-model="x.tasks">
                                <li ng-repeat="node in x.tasks" ui-tree-node ng-include="'nodes_renderer.html'"></li>
                            </ol>
                        </div>

通过点击按钮,它将添加节点,但在底部添加节点。我需要在顶部添加该节点。如何才能做到这一点?


x.task.push在数组的末尾添加项目。 这就是你需要改变的地方

ng-click='x.tasks.push({task: "New Task",depth:"2", tasks:[]})'

改为使用unshift

ng-click='x.tasks.unshift({task: "New Task",depth:"2", tasks:[]})'

作为参考:如何在JavaScript中的数组的开头添加新的数组元素?

链接地址: http://www.djcxy.com/p/19365.html

上一篇: How to add new node at top in ui

下一篇: How to merge 2 object in javascript