Angular material 角垫树:如何在顶部插入新项目?
我使用的是角材质2树组件。在提供的示例中,当您添加一个新项目时,编辑框显示在底部,如何将其添加到第一个位置,以便我们始终可以看到添加的编辑框,就像在我的用例中我可以添加许多新项目一样Angular material 角垫树:如何在顶部插入新项目?,angular-material,Angular Material,我使用的是角材质2树组件。在提供的示例中,当您添加一个新项目时,编辑框显示在底部,如何将其添加到第一个位置,以便我们始终可以看到添加的编辑框,就像在我的用例中我可以添加许多新项目一样 请参见ChecklistDatabase类中的,将insertItem()方法从更改为 /** Add an item to to-do list */ insertItem(parent: TodoItemNode, name: string) { if (parent.children) {
请参见
ChecklistDatabase
类中的,将insertItem()
方法从更改为
/** Add an item to to-do list */
insertItem(parent: TodoItemNode, name: string) {
if (parent.children) {
//parent.children.push({item: name} as TodoItemNode);
parent.children.splice(0,0,{item: name} as TodoItemNode);
this.dataChange.next(this.data);
}
}
Stackblitz
在我的代码中,我使用unshift()
插入项(父项:FileNode,名称:string){
const child={name:name,'parent_id':parent.parent_id};
if(父项、子项){
父项。子项。取消移位(子项);
this.dataChange.next(this.data);
}否则{
parent.children=[];
父项。子项。取消移位(子项);
this.dataChange.next(this.data);
}
insertItem(parent: FileNode, name: string) {
const child = <FileNode>{ name: name,'parent_id': parent.parent_id};
if (parent.children) {
parent.children.unshift(child);
this.dataChange.next(this.data);
} else {
parent.children = [];
parent.children.unshift(child);
this.dataChange.next(this.data);
}