我想延迟加载 cacader 的数据。但是失败了,因为在加载函数中 this=undefined。该功能在组件中定义,并且组件中的其他功能运行良好。请帮忙,谢谢。
<nz-cascader
\[nzLoadData\]\="loadCityBuildingData"
\[(ngModel)\]\="selectedLocation"
(ngModelChange)\="onNewLocationModalChanges($event)"
\> </nz-cascader>
loadCityBuildingData(node: NzCascaderOption, index: number): PromiseLike<void\> {
console.log(this);
return new Promise(resolve => {
if (index < 0) {
this.cityService.getCities().subscribe(item => {
const cities = \[\];
item.forEach(city => {
cities.push({value: city.id, label: city.name});
});
node.children \= cities;
resolve();
});
} else if (index === 0) {
this.buildingService.getBuildingsByCityId(node.value).subscribe(item => {
const buildings = \[\];
item.forEach(building => {
buildings.push({value: building.id, label: building.name, isLeaf: true});
});
node.children \= buildings;
resolve();
});
}
});
}