我有以下代码块:
<div className="max">
{Math.max.apply(
Math,
items.feeds.map(function(o) {
const temp = 34;
if(o.field1 <= temp) {
return <b>{o.field1}</b>; //return NaN
}
else {
return o.field1;
}
})
)}
</div>
但是,if语句返回NaN。如果我只返回o.field1,它就可以工作。像这样:
items.feeds.map (function (o) {return o.field1}
我的if语句中有问题吗?我想让o.field1的值满足打印到屏幕时的条件是粗体。
答案 0 :(得分:1)
Math.max
返回一个数字:
返回值:给定数字中的最大值。如果至少 参数不能转换为数字,则返回NaN。
您返回的是<b>{o.field1}</b>
-无法将其转换为数字。以后用<b>
标签包裹返回的数字。