首页 > 解决方案 > Angular-tree-component ASync Child 未加载?

问题描述

我正在使用 npm install --save angular-tree-component 当我单击父节点时未加载子节点它显示“正在加载...”消息这是我的代码

options: ITreeOptions = {
    getChildren: this.getChildren.bind(this)
  };

  getChildren(node: any) {
    debugger
    this.TreeService.getChildren((callback) => {
      this.asyncChildren = callback;             
      const newNodes = this.asyncChildren.map((c) => Object.assign({}, c));
      return new Promise((resolve, reject) => {
        setTimeout(() => resolve(newNodes), 1000);
      });
    });
  }

标签: npmsaveinstallationangular-tree-component

解决方案


看起来您缺少返回承诺(打字稿定义有点打开,它只期望“任何”作为返回值)。如此处所述您必须返回一个承诺或一个数组。

getChildren(node: any) {
debugger
return /*missing return*/ this.TreeService.getChildren((callback) => {
  this.asyncChildren = callback;             
  const newNodes = this.asyncChildren.map((c) => Object.assign({}, c));
  return new Promise((resolve, reject) => {
    setTimeout(() => resolve(newNodes), 1000);
  });
});

}


推荐阅读