Backbone视图渲染React组件

社会主义新天地 提交于 2020-03-26 19:32:02

 1 <!DOCTYPE html>
 2 <html>
 3   <head>
 4     <meta charset="UTF-8" />
 5     <title></title>
 6     <script src="react/react-0.14.7/build/react.js"></script>
 7     <script src="react/react-0.14.7/build/react-dom.js"></script>
 8     <script src="react/browser.min.js"></script>
 9     <script type="text/ecmascript" src="app/scripts/vendor/jquery.min.js"></script>
10       <script src="app/scripts/vendor/underscore.js"></script>
11        <script src="app/scripts/vendor/backbone.js"></script>
12   </head>
13   <body>
14     <div id="example"></div>
15     <script type="text/babel">
16       var HelloMessage = React.createClass({
17         render: function() {
18           return <h1>Hello World!{this.props.name}</h1>;
19         }
20       });
21 
22       ReactDOM.render(
23         <HelloMessage />,
24         document.getElementById('example')
25       );
26 
27 
28        var MyView = Backbone.View.extend({
29   el: 'body',
30   template: '<div class="widget-container"></div>',
31   render: function() {
32     this.$el.html(this.template);
33     var HM=React.createFactory(HelloMessage);   
34     ReactDOM.render(new HM({name:'xxxxx'}), this.$('.widget-container').get(0));
35     // ReactDOM.render( HM({name:'xxxxx'}), this.$('.widget-container').get(0));
36     //  ReactDOM.render(<HM  name='xiaoxiao'/>), this.$('.widget-container').get(0));
37     //  ReactDOM.render(<HelloMessage  name='xiaoxiao'/>), this.$('.widget-container').get(0));
38     return this;
39   }
40     });
41 
42         new MyView().render();
43     </script>
44   </body>
45 </html>

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!