npm - 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);
});
});
}
解决方案
看起来您缺少返回承诺(打字稿定义有点打开,它只期望“任何”作为返回值)。如此处所述,您必须返回一个承诺或一个数组。
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);
});
});
}
推荐阅读
- xpath - 具有多个文本元素的 contains() 的 XPath 查询
- vba - 我可以在我的用户表单中没有 commandbutton1 吗?
- asp.net - 使用 Response.Redirect() 重定向到第三方 URL 时发布数据
- java - IllegalStateException:无法加载指定的 mime 类型映射文件 [org/springframework/mail/javamail/mime.types]
- javascript - 需要一些关于如何在 JavaScript 中使用函数式编程来重用函数的想法
- php - 我们可以用 apache kafka 替换 cron 作业吗
- linux - 关于如何在 Windows 上使用 VirtualBox 和 Vagrant 搭建 Ubuntu 虚拟环境
- java - 如何使用 wsld 从我的 Api 响应中获取数据 XML 或属性值?
- html - 在电子邮件客户端中测试时 HTML 内容发生变化
- python-3.x - python 3双循环理解说明