当我有以下数据时。
private static _docFields: TreeData[] = [
{
id: 0,
id: NodeType.Annotation,
label: 'Annotations',
children: [],
},
如果我按照以下说明进行操作,则它是反应性的。
ApiService.post(
'documentAnnotation/annotations', { projectId: AppStore.projectId },
).then((responseData: KeyValue[]) => {
// TODO: Can't there be a mapper which can transform the results?
responseData.forEach((documentAnnotation) => {
AppStore.docFields.find((x) => x.id === NodeType.Annotation)!.children!.push({
label: documentAnnotation.value,
value: documentAnnotation.key,
});
});
});
但是当我有以下数据时,
private static _docFields: TreeData[] = [
{
id: '0.' + NodeType.Annotation,
label: 'Annotations',
nodeType: NodeType.Annotation,
children: [{
id: '0.' + NodeType.SinglePageAnnotation,
label: 'Single',
children: [],
nodeType: NodeType.SinglePageAnnotation,
}, {
id: '0.' + NodeType.MultiPageAnnotation,
label: 'Multiple',
children: [],
nodeType: NodeType.MultiPageAnnotation,
}],
},
而且我也遵循,它不是被动的。我该怎么办?
AppStore.docFields
.find((x) => x.nodeType === NodeType.Annotation)!.children!
.find((y) => y.nodeType === NodeType.SinglePageAnnotation)!.children!.push({
label: documentAnnotation.value,
value: documentAnnotation.key,
});
我具有如下所示的绑定元素UI树。
<el-tree :data="AppStore.docFields">