【发布时间】:2016-12-08 18:57:11
【问题描述】:
我一直在尝试将自己的额外道具传递给使用 .map 函数创建的孩子,但我未能成功传递它们。
这是我的代码:
export const CommentsListShanghai = (props) => {
const newTimestamp = props.timestamp;
console.log(newTimestamp);
const comments = props.comments;
if (comments.length > 0 ) {
return (
<ButtonToolbar className="comment-list">
{comments.map((com) => {
return (
com.adminSpark ?
<CommentsModal
className="comments-modal"
data-comments-modal={props.newTimestamp}
key={ com._id }
comment={ com }
city={com.city}
person={com.person}
location={com.location}
title={com.title}
content={com.content}
fileLink={com.fileLink}
timestamp={com.timestamp}
createdBy={com.createdBy}
/> :
<CommentsModal
key={ com._id }
comment={ com }
city={com.city}
person={com.person}
location={com.location}
title={com.title}
content={com.content}
fileLink={com.fileLink}
timestamp={com.timestamp}
createdBy={com.createdBy} />
)
})}
</ButtonToolbar>
);
} else {
return (
<Alert bsStyle="warning">No sparks yet. Please add some!</Alert>
);
}
};
CommentsListShanghai.propTypes = {
comments: React.PropTypes.array,
};
我能够传递我创建的 cmets const 的所有道具,问题是除了这些道具之外,我还需要传递 CommentsListShanghai 中可用的额外道具。我怎样才能将额外的道具传递给这个数组?
我可以毫无问题地使用 console.log(newTimestamp),但不明白如何将其传递给 .map 函数。
【问题讨论】:
标签: javascript reactjs meteor