<kendo-treeview #departmentTree [nodes]="departmentList" textField="EnName" kendoTreeViewExpandable
kendoTreeViewSelectable kendoTreeViewHierarchyBinding [hasChildren]="hasChildren"
[children]="fetchChildren" (nodeClick)="onNodeClick($event)">
<ng-template kendoTreeViewNodeTemplate let-dataItem>
<span class="tree-node">
{{dataItem.EnName}} </span>
</ng-template>
</kendo-treeview>
public fetchChildren = (node: any): Observable < any[] > => {
return this.httpService.getDepartment(node.DepartmentId);
}
我想在不刷新的情况下将新节点插入到现有的 Treeview 中。 (如插入现有数组)我尝试将子节点插入选定的数据项
this.selectedNode.items.push(newItem)
我没有找到任何文档
最佳答案
i want to insert new nodes into existing treeview
前端框架(包括 Angular)背后的整个想法是使用您提供的声明性模板(如
@Component#template
或 @Component#templateUrl
)更改数据并让框架更改 View 。without refresh
单页应用程序中的所有内容都无需刷新即可完成。这就是重点,这就是它们被称为单页应用程序的原因:浏览器从服务器获取的传统页面没有概念:所有更改都是通过客户端 JavaScript 完成的,包括“页面”更改由路由器的 JavaScript 实现(常见的选择是
@angular/router
)。(like push into the existing array )
这正是你必须做的。 Angular 将处理更新 View ,除非组件构建不正确或严重优化,因此需要手动更改检测周期触发器,但您可能知道这些情况何时出现,所以我认为您不必担心.
i try to push child nodes into selected dataItem this.selectedNode.items.push(newItem)
那就有什么不对了。尝试将整个数组作为 JSON 打印到页面以查看它是否发生变化:
{{ selectedNode.items | json }}
。我将用具体的原因更新答案,说明为什么在添加缺少的详细信息时您没有看到 View 发生变化。以上是可以帮助其他人更好地理解为什么 View 可能不会更新的一般想法。
关于angular - 当 child 从远程获取时如何动态添加或删除节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55897623/