当我尝试循环状态数据时出现以下错误类型 '{ [key: number]: any[]; 上不存在属性 'length' }'。国家声明export interface State { resultData:{ [key: number]: any[] }; }类声明export class AccountComp extends React.PureComponent<Props, State> { constructor(props: Props) { super(props); this.state = { resultData: {}, }; } update function showing issue in second for loop .Property 'length' does not exist on type '{ [key: number]: any[]; }'.update = () => { for (let i = 0; i < 7; i++) { for (let j = 0; j < this.state.resultData.length; j++) // showing issue in this line { } } }
1 回答
慕斯709654
TA贡献1840条经验 获得超5个赞
在界面中,resultData不是数组。resultData[key]是数组。所以尝试以下
update = () => {
for (let i = 0; i < 7; i++)
{
for (let j = 0; j < this.state.resultData[i].length; j++)
{
// do something
}
}
}
添加回答
举报
0/150
提交
取消