当使用 primeng 选择 child 时,我必须将连字符放在 parent 节点上
I have to put the hyphen on the parent node when a child is selected with primeng
这是 Typescript //二分体编码
Ngonint-->
ngOnInit() {
if(this.title === "Create"){
this.dataProfilo = {}
this.dataProfilo.function = [];
this.service.getTree().subscribe(
(res) => {
this.node= res.nodeTree;
},
)
}else{
this.dataProfilo={...this.profilo};
this.service.getProfiloById(this.profilo.id).subscribe(
(res) =>{
if(res && res.nodeTree.length >0){
this.node= res.nodeTree;
res.nodeTree.forEach(elem => {
this.checkSelectionNode(elem);
});
if(res && res.nodeTree.length >0){
this.node= res.nodeTree;
res.nodeTree.forEach(elem => {
this.uncheckSelectionNode(elem);
});
}
}
},
(error)=> {
});
}
}
如果检查节点
checkSelectionNode(node) {
if (node.data.flag) {
this.selectedFile.push(node);
}
if (node && node.children && node.children.length > 0) {
node.children.forEach(childNode => {
this.checkSelectionNode(childNode);
}
);
}
}
**if node are unchecked**
uncheckSelectionNode(node) {
if (node.data.flag == false) {
this.unselectedFile.push(node);
}
if (node && node.children && node.children.length > 0) {
node.children.forEach(childNode => {
this.uncheckSelectionNode(childNode);
}
);
}
}
如果选择节点 - 父亲和 child--------------------
nodeSelect(event){
if(event.node.children && event.node.children.length > 0){
event.node.children.forEach(element => {
const functionFK = this.checkChildrenNode(element);
if(functionFK){
let checkNodeExist = false;
this.dataProfilo.function.forEach(element => {
if(element === functionFK){
checkNodeExist = true;
}
});
if(!checkNodeExist){
this.dataProfilo.function.push(functionFK);
}
}
});
} else {
if(event.node.data.functionFK){
let checkNodeExist = false;
this.dataProfilo.function.forEach(element => {
if(element === event.node.data.functionFK){
checkNodeExist = true;
}
});
if(!checkNodeExist){
this.dataProfilo.function.push(event.node.data.functionFK);
}
}
}
}
**OTHER METHOD!**
nodeUnselect(event) {
const nodes = [];
if (event.node.children && event.node.children.length > 0) {
event.node.children.forEach(element => {
const functionFK = this.checkChildrenNode(element);
if (functionFK) {
nodes.push(functionFK);
}
});
this.dataProfilo.function = this.dataProfilo.function.filter(val => !nodes.includes(val));
} else {
if (event.node.data.functionFK) {
this.dataProfilo.function = this.dataProfilo.function.filter(
elem => {
return elem != event.node.data.functionFK
}
);
}
}
}
*if childrean are checked - BOTH FATHER AND CHILDREN
- 如果nodes和children存在并且length的node长于0,我做一个forEach/a循环看他们是否被选中
checkChildrenNode(node): any {
if (node && node.children && node.children.length > 0) {
node.children.forEach(childNode => {
this.checkChildrenNode(childNode);
});
} else {
return node.data.functionFK;
}
}
changeAssegnate(event:any){
if(event.checked){
this.toggle = 'assegnate';
}else{
this.toggle = null;
}
console.log(event)
}
}
这是我的代码。我正在使用 primeng - Angular。 有什么想法吗?
如果您查看 primeng 的树文档,这是常见的行为 here