我应该做一棵Primeng树。这是我的模型。
export interface Profiles {
active?: true,
description?: string,
function?: [
string
],
id?: number,
macroFunction?: string,
name?: string,
nodeTree?: [
{
children?: [
string
],
data?: {
description?: string,
flag?: true,
functionFK?: string,
id?: number,
order?: number,
parent?: number
}
}
]
}
我不知道如何进行 http 调用和其他操作。
我想过这样的事情:服务:
postProfiles(): Promise<Profiles > {
const url = 'profiles/create';
return this.http.post<Profiles >(url, {})
.toPromise()
}
ts --> http
node: Profile[];
selectedNode: Profile;
ngOnInit() {
this.nodeService.postProfiles().then(node=> this.selectedNode= node);
}
HTML
<p-tree [value]="node" selectionMode="single" [(selection)]="selectedNode"></p-tree>
有人能帮我吗?怎么了?提前致谢!
完毕!我希望它会有用
node:any;
this.ricercaService.getTree().subscribe( (res) => {
this.node = res.nodeTree;
},
(error) => { c
onsole.log(error);
});
HTML - </p>
<p-tree *ngIf="node" [value]="node" selectionMode="checkbox" [(selection)]="selectedNode"> <ng-template let-node pTemplate="default"> <b>{{ node.data.description }}</b> </ng-template> </p-tree> –