zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    钱伟长的养生之道:每天步行三千步
    GBDT 深入理解
    整形数据的存储方式
    进制基础学习
    C语言运算符(注意事项)
    PHP文件锁
    gcc options选项的优化及选择
    Datenode无法启动
    如何使用WebUploader。
    thinkphp如何实现伪静态
  • 原文地址:https://www.cnblogs.com/streamice/p/react_native_ajax.html
Copyright © 2011-2022 走看看