Skip to content

Commit 5d3ee53

Browse files
committed
完成评论列表硬编码数据
1 parent 684b2b8 commit 5d3ee53

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

public/scripts/tutorial.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
class Comment extends React.Component{
1+
const data = [
2+
{id: 1, author: "Pete Hunt", text: "This is one comment"},
3+
{id: 2, author: "Jordan Walke", text: "This is *another* comment"}
4+
];
5+
6+
class Comment extends React.Component {
27
constructor(props) {
38
super(props);
49
}
510

11+
rawMarkup() {
12+
let md = new Remarkable();
13+
let rawMarkup = md.render(this.props.children.toString());
14+
return {__html: rawMarkup};
15+
}
16+
617
render() {
18+
// let md = new Remarkable();
719
return (
820
<div className="comment">
921
<h2 className="commentAuthor">
1022
{this.props.author}
1123
</h2>
12-
{this.props.children}
24+
<span dangerouslySetInnerHTML={this.rawMarkup()}/>
1325
</div>
1426
);
1527
}
@@ -21,9 +33,18 @@ class CommentList extends React.Component {
2133
}
2234

2335
render() {
36+
let commentNodes = this.props.data.map(function (comment) {
37+
return (
38+
<Comment author={comment.author} key={comment.id}>
39+
{comment.text}
40+
</Comment>
41+
)
42+
});
43+
44+
2445
return (
2546
<div className="commentList">
26-
Hello, world! I am a CommentList.
47+
{commentNodes}
2748
</div>
2849
);
2950
}
@@ -52,16 +73,14 @@ class CommentBox extends React.Component {
5273
return (
5374
<div className="commentBox">
5475
<h1>Comments</h1>
55-
<CommentList/>
76+
<CommentList data={this.props.data}/>
5677
<CommentFrom/>
5778
</div>
5879
);
5980
}
6081
}
6182

62-
63-
6483
ReactDOM.render(
65-
<CommentBox />,
84+
<CommentBox data={data}/>,
6685
document.getElementById('content')
6786
);

0 commit comments

Comments
 (0)