Flux todoMVC 为什么要费那么多力气实现一个功能!!!!,这样的的好处是神马?
我设置全局的_list 数组就搞定了,谁能告诉我费力气绕弯写代码的好处!!!
你看我这样直接把_lists=[]写到外面不是很简单吗,为什么还要用Flux.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="../build/react.js"></script>
<script src="../build/JSXTransformer.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/jsx">
var _lists=[];
var LikeButton = React.createClass({
handleClick: function(e) {
var v = this.refs['myTextInput'].getDOMNode().value;
_lists.push(v);
this.setState({
lists: _lists
});
},
render: function() {
var lists = _lists;
var i=0;
return (
<div>
<ol>
{
lists.map(function (list) {
i++;
return <li key={i}>{list}</li>
})
}
</ol>
<input type="text" ref="myTextInput" placeholder="input fuck there" />
<button onClick={this.handleClick}> Add Fuck </button>
</div>
);
}
});
React.render(
<LikeButton />,
document.getElementById('example')
);
</script>
</body>
</html>
超越神的男人
10 years, 4 months ago