Javascript 财产';长度';不存在于类型';{[key:number]:任意[];}';。in-React/Angular in-state变量
当我尝试循环状态数据时,出现以下错误 类型“{[key:number]:any[];}”上不存在属性“length”。 国家宣言Javascript 财产';长度';不存在于类型';{[key:number]:任意[];}';。in-React/Angular in-state变量,javascript,angular,reactjs,Javascript,Angular,Reactjs,当我尝试循环状态数据时,出现以下错误 类型“{[key:number]:any[];}”上不存在属性“length”。 国家宣言 export interface State { resultData:{ [key: number]: any[] }; } export class AccountComp extends React.PureComponent<Props, State> { constructor(props: Props) {
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
{
}
}
}
类声明
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
{
}
}
}
导出类AccountComp扩展了React.PureComponent{
建造师(道具:道具){
超级(道具);
this.state={
结果数据:{},
};
}
更新函数,在第二个for循环中显示问题。
类型“{[key:number]:any[];}”上不存在属性“length”。
更新=()=>{
for(设i=0;i<7;i++)
{
for(让j=0;j
在界面中,resultData
不是数组。resultData[key]
是数组。请尝试以下操作
update=()=>{
for(设i=0;i<7;i++)
{
for(设j=0;j
您正在将resultData:{}
初始化为对象文本,而不是数组文本[]