react native for android(ajax)

通过ajax加载数据,废话不多说,直接上代码

 1 <!DOCTYPE html>
 2 <html>
 3   <head>
 4     <script src="../build/react.js"></script>
 5     <script src="../build/react-dom.js"></script>
 6     <script src="../build/browser.min.js"></script>
 7     <script src="../build/jquery.min.js"></script>
 8   </head>
 9   <body>
10     <script type="text/babel">
11 var UserGist = React.createClass({
12   getInitialState: function() {
13     return {
14       username: '',
15       lastGistUrl: ''
16     };
17   },
18 
19   componentDidMount: function() {
20     $.ajax({
21                     url: this.props.source,
22                     type: "GET",                    
23                     dataType: 'json',                   
24                     success: function (resp) {
25                         var lastGist = resp[0]; 
26             this.setState({
27             username: lastGist.owner.login,
28             lastGistUrl: lastGist.html_url
29         });
30        }.bind(this),
31     });   
32   },
33     render: function() {
34     return (
35       <div>
36         {this.state.username}'s last gist is <a href={this.state.lastGistUrl}>here</a>.
37       </div>
38     );
39   }
40 });
41 
42 ReactDOM.render(
43   <UserGist source="https://api.github.com/users/octocat/gists" />,
44   document.body
45 );
46     </script>
47   </body>
48 </html>

 

posted @ 2016-01-23 09:46  streamice  阅读(556)  评论(0编辑  收藏  举报