【发布时间】:2023-01-08 03:52:14
【问题描述】:
this.items 是从数据库中读取的项目列表。对于列表中的每个项目,我想创建 Shape.Rect 对象并将它们加载到名为 stencil.load 的函数中。此功能无法动态添加项目,因此我需要创建所有项目并同时加载它们。
我试过执行forEach,如下面的代码示例所示,但它只注册了列表中的最后一项。知道该怎么办吗?
.
.
.
this.items.forEach((item) => {
const result = new Shape.Rect({
shape: 'rect',
label: item.component_name,
id: item.component_id,
x: 5,
y: 50,
width: 100,
height: 25,
});
stencil.load([result], 'group1');
});
.
.
.
【问题讨论】:
标签: javascript arrays javascript-objects antv