angular - 当 child 从远程获取时如何动态添加或删除节点

标签 angular kendo-ui kendo-ui-angular2 kendo-treeview

   <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/

相关文章:

css - Loader 没有覆盖整个页面

Angular 辅助路由 - 无法在同一个导航调用中导航和清除辅助路由?

javascript - 为什么 Angular 2 的 CanActivate 返回 Observable<boolean> 而不是 Promise?

javascript - Angular Material - 为树添加分支线?

kendo-ui - TypeScript 定义,其中属性类型已知但名称*不是*

angular - Kendo UI Angular 2 Grid Excel 导出

angular6 - 通过 ngIf 加载模块时,Angular Datepicker 本地化的 Kendo UI 不起作用

javascript - 更改隐藏字段值时的 Kendo UI 网格触发更新方法

c# - Scrollview 和 Mozilla PDF.js 的滚动错误

css - 悬停效果上的 Angular Kendo Grid Row