-
Notifications
You must be signed in to change notification settings - Fork 1
/
C09_01.js
45 lines (40 loc) · 1.11 KB
/
C09_01.js
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
import React, { Component } from 'react';
import fetchJsonp from 'fetch-jsonp';
class C09_01 extends Component {
constructor(props) {
super(props);
this.state = {
list:[]
};
}
getDate=()=>{
var api="http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20";
fetchJsonp(api)
.then(function(response) {
return response.json()
}).then((json)=> {
console.log(json);
this.setState({
list:json.result
})
}).catch(function(ex) {
console.log('parsing failed', ex)
})
}
render() {
return (
<div>
<h2>演示如何从服务器获得信息</h2>
<button onClick={this.getDate} >获取数据</button> <hr/>
{
this.state.list.map((value,key)=>{
return(
<li key={key}>{value.title}</li>
)
})
}
</div>
);
}
}
export default C09_01;