首页 > 其他 > 详细

react-conponent-todo

时间:2016-02-23 12:58:16      阅读:190      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
  <head>
    <script src="../../build/react.js"></script>
    <script src="../../build/react-dom.js"></script>
    <script src="../../build/browser.min.js"></script>
  </head>
  <body>
    <div id="example"></div>
    <script type="text/babel">
    var TodoList = React.createClass({
      render: function() {
        var createItem = function(item) {
          return <li key={item.id}>{item.text}</li>;
        };

      return <ul>{this.props.items.map(createItem)}</ul>;
      },
    });
    var TodoApp = React.createClass({
        getInitialState: function() {
          return {items: [], text: ‘‘};
        },
        
        onChange: function(e) {
          this.setState({text: e.target.value});
        },

        handleSubmit: function(e) {
          e.preventDefault();
          var nextItems = this.state.items.concat([{text: this.state.text, id: Date.now()}]);
          var nextText = ‘‘;
          this.setState({items: nextItems, text: nextText});
        },

        render: function() {
          return (
            <div>
              <h3>TODO</h3>
              <TodoList items={this.state.items} />
              <form onSubmit={this.handleSubmit}>
                <input onChange={this.onChange} value={this.state.text} />
                <button>{‘Add #‘ + (this.state.items.length + 1)}</button>
              </form>
            </div>
          );
        },
    });

    ReactDOM.render(<TodoApp />, document.getElementById(‘example‘));
    </script>
  </body>
</html>

 

react-conponent-todo

原文:http://www.cnblogs.com/cynthia-wuqian/p/5209439.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!