HarmonyOS selectedCityData 数组 Object is possibly 'undefined'. <ArkTSCheck>
步骤一: CYMyProfileImpInformationStuTeacherCityPage路由跳转到达CYMyProfileImpInformationStuTeacherPage页面。
@Entry
@Component
export struct CYMyProfileImpInformationStuTeacherCityPage
export class CityModel{
provid?: number;
name?: string;
}
export default class CityModelAllInfomation{
type?: string;
selectedCityData?: CityModel[];
}
@State selectedCityData: CityModel[] = [];
let cityModelAllInfomation: CityModelAllInfomation = {
selectedCityData: this.selectedCityData,
}
router.back({
url: 'pages/CYMyProfileImpInformationStuTeacherPage',
params: cityModelAllInfomation
})
步骤二 :CYMyProfileImpInformationStuTeacherPage 页面, 获取值。
@State params: CityModelAllInfomation = router.getParams()
this.params.selectedCityData.length
问题:selectedCityData 数组Object is possibly 'undefined',尝试使用as CityModel[],也没有效果。
this.selectedCityData = this.params.selectedCityData as CityModel[];
想取出数组信息,拼接地区,如北京 北京市 朝阳区。
HarmonyOS
赞
收藏 0
回答 1
待解决
这边用以下demo复现问题,传CityModel[]这个数组的话,是没问题的: