1
我一直在PrimeNg的树模块工作几天,我一直在编写几乎所有我想要它做的自定义功能。不过,由于回调被称为后处理,我仍然在自定义copyTo
函数中遇到对象引用的问题。因此,我正在寻找一种优雅的方式来中断拖放处理程序,以便我可以深度复制数据以进行更精细的控制。我觉得我应该考虑扩展课程,这样我就可以重写插件的功能,但我不确定升级时是否会对线路造成更多伤害。Angular 4 PrimeNg树拖放复制到
任何意见或“如何”的建议非常感谢!
下面的代码接受一个带有已知索引的元素,并将其重新插入到被拖动的树中,从而将树从一棵树复制到另一棵树。但是,这仅适用于已知索引,并且不支持嵌套节点的深度不同。
copyToTree: any = []; // tree obj cache
staticTree: any = []; // tree obj cache
// Fires when node is dropped on copyToTree
dropOnCopyTo(event: any) {
let dragged: any = event.dragNode;
if(dragged.field_name == null) { // dragged from staticTree
// re-add copy to correct position in staticTree
let copy: any = this.deepCopy(dragged);
this.staticTree.children.splice(copy.index, 0, copy);
// Update field_name of dragged in copyToTree
dragged.field_name = 'new_' + Date.now();
}
}
你可以发布你到目前为止尝试过的代码吗? – Cody
更新了我目前的复制功能,但如前所述,它不支持非静态树节点复制 – navybofus