Javascript 儿童是反应性的,但儿童的儿童不是反应性的-vue
当我有以下数据Javascript 儿童是反应性的,但儿童的儿童不是反应性的-vue,javascript,typescript,vue.js,vuejs2,vue-component,Javascript,Typescript,Vue.js,Vuejs2,Vue Component,当我有以下数据 private static _docFields: TreeData[] = [ { id: 0, id: NodeType.Annotation, label: 'Annotations', children: [], }, 如果我跟随,它是反应性的 ApiService.post( 'documentAnnotation/annotations', { projectId: AppStor
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">