【问题标题】:got error Expected an assignment or function call and instead saw an expression no-unused-expressions得到错误期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions
【发布时间】:2019-01-28 09:12:54
【问题描述】:

我想通过一个命令在 div 中显示完整的对象,包括 cmets(它是对象数组),但我在 cmets 的 map 函数上遇到错误。请帮我解决这个问题 ....

 const fields2 = [

    {
        month: 30,
        unitrate: 2,
        budget: 6000,
        comments: [
            {
                id: 4500,
                rating: 11111111111,
                comment: "Imagine all the eatables, living in conFusion!",
                author: "John Lemon",
                date: "2012-10-16T17:57:28.556094Z"
            },
            {
                id: 1,
                rating: 22222222222,
                comment:
                    "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!",
                author: "Paul McVites",
                date: "2014-09-05T17:57:28.556094Z"
            },
]
}
];


render() {

        return (
            <div>

                { fields2.map((ob,index)=>{ return (ob.month  +" " + ob.comments.map((ok,index)=>{ ok  }   )) }) }
            </div>
        )
    }

【问题讨论】:

  • { fields2.map((ob,index)=>{ return (ob.month +" " + JSON.stringify(ob.cmets)) }) }

标签: reactjs


【解决方案1】:

你可以使用下面提到的代码

 { fields2.map((ob,index)=>{ return (ob.month  +" " + JSON.stringify(ob.comments,null,4)) }) }

【讨论】:

    猜你喜欢
    • 2020-06-04
    • 2021-11-17
    • 2021-08-23
    • 2019-08-15
    • 2020-12-10
    • 2020-04-21
    • 2019-11-23
    • 1970-01-01
    • 2020-11-20
    相关资源
    最近更新 更多