码迷,mamicode.com
首页 > 其他好文 > 详细

React组件-mixin

时间:2015-12-19 00:07:03      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

一、组件

技术分享

二、代码

 1 <!DOCTYPE html>
 2 <html lang="zh-cn">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Mixin</title>
 6 </head>
 7 <body>
 8     <script src="./react-0.13.2/react-0.13.2/build/react-with-addons.js"></script>
 9     <script src="./react-0.13.2/react-0.13.2/build/JSXTransformer.js"></script>
10     <script type="text/jsx">
11         // var BindingExample = React.createClass({
12         //     getInitialState: function() {
13         //         return {
14         //             text: ‘‘
15         //         }
16         //     },
17         //     handleChange: function(event) {
18         //         this.setState({text: event.target.value})
19         //     },
20         //     render: function() {
21         //         return <div>
22         //             <input type="text" placeholder="请输入内容" onChange={this.handleChange} />
23         //             <p>{this.state.text}</p>
24         //         </div>
25         //     }
26         // })
27         var BindingMixin = {
28             handleChange: function(key) {
29                 var that = this
30                 var newState = {}
31                 return function(event) {
32                     
33                     newState[key] = event.target.value
34                     that.setState(newState)
35                 }
36             }
37         }
38         var BindingExample = React.createClass({
39             mixins: [React.addons.LinkedStateMixin],
40             getInitialState: function() {
41                 return {
42                     text: ‘‘,
43                     comment: ‘‘,
44                 }
45             },
46             render: function() {
47                 return <div>
48                     <input type="text" placeholder="请输入内容" valueLink={this.linkState(text)} />
49                     <textarea valueLink={this.linkState(comment)}></textarea>
50                     <p>{this.state.text}</p>
51                     <p>{this.state.comment}</p>
52                 </div>
53             }
54         })
55         React.render(<BindingExample></BindingExample>, document.body);
56     </script>
57 </body>
58 </html>

 

React组件-mixin

标签:

原文地址:http://www.cnblogs.com/shamgod/p/5058419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!