React(0.13) 定义一个动态的组件(属性)

<!DOCTYPE html>
<html>
    <head>
        <title>React JS</title>
        <script src="../build_0.13/react.js"></script>
        <script src="../build_0.13/JSXTransformer.js"></script>
        <script>
            function dateToString(d){
                return [d.getFullYear(), d.getMonth()+1, d.getDate()].join('-');
            }
        </script>
    </head>
    <body>
        
        <script type="text/jsx">
            var h1 = "question";
            var id = "caodao";
            var Divider = React.createClass({
                    render:function(){
                        return (<div className="divider" id={id} >
                                    <h1>{h1}</h1>
                                </div>
                                );
                    }
                });
            
            //将组件加到对应的元素上
            React.render( <Divider />, document.getElementById('example') );
    
        </script>
        <div id="example">
        
        </div>
    </body>
</html>

posted @ 2016-03-24 13:29  天道酬勤,坚持!  阅读(1262)  评论(0编辑  收藏  举报