-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPortableLibraryP1.jsx
55 lines (55 loc) · 1.25 KB
/
PortableLibraryP1.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var NewBook = React.createClass({
render: function(){
return(
<div class="book-model add-book" ></div>
)
}
});
var Book = React.createClass({
render: function(){
var bookName = this.props.book.bookName;
var bookIntro = this.props.book.bookIntro;
var bookImgAddress = this.props.book.bookImgAddress;
return (
<div class="book-model">
<img src={bookImgAddress} />
<div class="book-info">
<h1>{bookName}</h1>
<p>{bookIntro}</p>
</div>
</div>
)
}
});
var BooksExhibitContainer = React.createClass({
getInitialState: function(){
return {
books: []
}
},
componentDidMount: function(){
$.ajax({
url: this.props.url,
dataType: 'json',
type: 'get',
success: function(response){
this.setState({
books: response.books
});
}.bind(this),
error: function(xhr, status, err){
console.log(this.props.url, status, err.toString());
}.bind(this)
});
},
render: function(){
var bookCollector = [];
this.state.books.forEach(function(book){
bookCollector.push(<Book book={book}/>);
});
return(
<div class="books-container">{bookCollector}</div>
)
}
});
React.render(<BooksExhibitContainer url="booksInfo.json"/>, document.body);