在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 這個為什么會報(bào)auditRuleList.result.map is not a

這個為什么會報(bào)auditRuleList.result.map is not a function這個錯呢?

這個為什么會報(bào)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);
回答
編輯回答
遲月

因?yàn)?code>auditRuleList.result不是數(shù)組,原型鏈上不存在map方法

2018年7月24日 21:44
編輯回答
涼汐
(1)TypeError類型的錯誤: 對一個變量的值做不合理的操作 如對非函數(shù)的變量進(jìn)行函數(shù)調(diào)用 或者引用null或undefined類型的值得屬性等等
(2)map()是數(shù)組(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} />) :[]:[];
2018年7月29日 22:34