在ngonInit的所有报告数据中添加一个“折叠”字段,将折叠字段向下传递到每个子项中,根据您向下传递的折叠字段将ngClass设置为“显示:阻止” /“显示:无”开关,设置onclick切换折叠字段的真/假]
import { Component, OnInit } from '@angular/core';
import { DisplayreportService } from './displayreport.service';
import { HttpClient } from '@angular/common/http';
import { Router , ActivatedRoute} from '@angular/router';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
expanded = new Array(3).fill(false);
datalis:string;
allReportCategories:any[];
reportsubCategory:any[];
reportByCategoryId:any[];
allReportsubCategory:any[];
reportCategoryIdparam:string;
constructor(public http: HttpClient, private _router: Router, private _displayreport: DisplayreportService) { }
ngOnInit() {
// this._displayreport.getallReportCategories().subscribe((data: any[]) => {
// this.allReportCategories = data;
// });
this.allReportCategories=this._displayreport.getallReportCategories().map((e) => {
e.collapse = false;
return e
});
console.log(this.allReportCategories)
//this._displayreport.GetreportByCategoryId(this.reportid)//.subscribe((data: any[]) => {
// this.reportByCategoryId = data;
//});
// this.reportid="3";
//this.reportByCategoryId=this._displayreport.GetreportByCategoryId////(this.reportid);
this.reportByCategoryId = this._displayreport.GetreportByCategoryId("3");
console.log("data by category id" + this.reportByCategoryId);
this.reportsubCategory=this._displayreport.getallReportsubCategory();
}
toggleAccordian(event, index) {
var element = event.target;
console.log("element is" +JSON.stringify(index) )
console.log("element is" +JSON.stringify(element) )
this.allReportCategories[index].collapse = !this.allReportCategories[index].collapse
// element.classList.toggle("active");
// if(this.allReportCategories[index].isActive) {
// this.allReportCategories[index].isActive = false;
// } else {
// this.allReportCategories[index].isActive = true;
// }
// this._displayreport.GetreportByCategoryId(index);
// console.log(this._displayreport.GetreportByCategoryId(index))
}
}