【发布时间】:2016-05-27 09:34:35
【问题描述】:
我目前正在处理来自 API 的 JSON 文件,如果字段为空,该文件不会添加密钥对。在尝试遍历整个 JSON 文件时,这让我很伤心。
我的代码目前是
var ListOfItems = React.createClass({
render: function () {
var itemList = jsonFile.data.map(function(item)
{
return <Item key={item.__key}
itemQuestion={item.question}
itemQuestionAnswer={item.answer.answer}
userName={item.user.name}
staffName={item.staff.name}
staffImage={item.staff.image_url} />
});
return (
<div>
<ul>{itemList}</ul>
</div>
);
}
});
当 item.answer.answer 没有价值时会报错。
任何帮助将不胜感激。
【问题讨论】:
标签: javascript reactjs react-jsx jsx