子类别列需要根据类别列值动态填充。当我尝试选择类别值时,它会填充子类别列中的所有行而不是特定行。
请建议如何更改特定行的值?
<p-column field="category" header="Category" [sortable]="true" [editable]="false">
<ng-template let-item="rowData" pTemplate="body">
<select [(ngModel)]="item.category" (ngModelChange)="populateSubcategory($event)" [ngStyle]='{"width": "100%","border": "true", "background": "rgba(255,255,255,0)"}'>
<option *ngFor="let row of categoryList" [value]="row.value">{{row.label}} </option>
</select>
</ng-template>
<p-column field="subcategory" header="Sub-Category" [sortable]="true" [editable]="false">
<ng-template let-item1="rowData" pTemplate type="body">
<select [(ngModel)]="item1.subcategory" [ngStyle]='{"width": "100%","border": "true", "background": "rgba(255,255,255,0)"}'>
<option *ngFor="let row of subCategoryList" [value]="row.value">row.label</option>
</select>
</ng-template>
</p-column>
populateSubcategory(event) {
this.itemService.getCategory().then(items => {
var foundIndex;
for (var key in items) {
if (items.hasOwnProperty(key)) {
for (var key1 in items[key])
{
if (items[key][key1] === event)
{
foundIndex=key;
}
}
}
}
var foundMember = items[foundIndex];
this.subCategoryList = [];
for (var key in foundMember) {
if (key === "sub-category") {
for (key1 in foundMember[key])
{
this.subCategoryList.push({ label: foundMember[key][key1], value: foundMember[key][key1] });
}
}
}
});
}