这个为什么会报auditRuleList.result.map is not a function这个错呢?

这个为什么会报TypeError: auditRuleList.result.map is not a function这个错呢?

import { Modal,Steps} from 'antd';
import React from 'react';
import {connect} from "react-redux";

const Step = Steps.Step;
class ApproveState extends React.Component{

constructor(props) {
    super(props);
    this.state={
        visible: false,
        auditor:false,

    };
}

componentWillMount() {

}

componentDidMount() {

}

render(){
    const {visible,onCancel,currentAudit,auditRuleList} = this.props;
    console.log(auditRuleList)
    const dataSource = auditRuleList ? auditRuleList.result ? auditRuleList.result.map((item,index)=><Step
        key={item.id} title={item.name} description={item.time} />) :[]:[];
   
    return (
        <Modal
            visible={visible}
            title={"审核情况"}
            width="80vw"
            onCancel={onCancel}
            onOk={onCancel}
        >

        <Steps progressDot current={5}>
                     {dataSource}
        </Steps>
        </Modal>
    );
}
}

function mapStateToProps(state) {

return {
    auditRuleList:state.approveReducer.auditRuleList,
}
}

function mapDispatchToProps(dispatch){

return{

}
}
export default connect(mapStateToProps,mapDispatchToProps)(ApproveState);
阅读 2.9k
2 个回答
(1)TypeError类型的错误: 对一个变量的值做不合理的操作 如对非函数的变量进行函数调用 或者引用null或undefined类型的值得属性等等
(2)map()是数组(Array)对象的方法: array.map(function(currentValue,index,arr))
 (3)改法:
const dataSource = auditRuleList ? (auditRuleList.result && Array.isArray(auditRuleList.result))? auditRuleList.result.map((item,index)=><Step
        key={item.id} title={item.name} description={item.time} />) :[]:[];

因为auditRuleList.result不是数组,原型链上不存在map方法

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题