gpt4 book ai didi

angularjs - 如何在ui-tree angular js的顶部添加新节点

转载 作者:行者123 更新时间:2023-12-04 19:37:13 24 4
gpt4 key购买 nike

在我的应用程序中,我使用了 angular 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:[]})'

供引用: How can I add new array elements at the beginning of an array in JavaScript?

关于angularjs - 如何在ui-tree angular js的顶部添加新节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39543807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com