var CommentInput = React.createClass({
getInitialState: function () {
return ({UserName: ''})
},
render: function () {
return (
<section style={DemoListHeader}>
<div>
<p style={DemoListLabelText}>请输入:</p>
<input style={DemoListInputText} type="text" name="addList" value={this.state.UserName}
onChange={this.handleChange} onKeyPress={this.setInputValue}/>
</div>
</section>
)
},
handleChange: function (ev) {
this.setState({UserName: '' + ev.target.value + ''});
},
setInputValue: function (ev){
if (ev.which == 13) {
this.props.onInput(this.state.UserName);
}
}
})
var CommentListDoingChildren = React.createClass({
render: function () {
return (
<li>
<input type="radio" style={{float:"left"}}/>
{this.props.name}
<p style={{float:"right"}}>删除</p>
</li>
)
}
});
var App = React.createClass({
getInitialState: function () {
return ({AppValue: []})
},
render: function () {
return (
<div>
<CommentInput onInput={this.handleOnInput}/>
<ol>
<CommentListDoingChildren name={this.state.AppValue} />
</ol>
</div>
);
},
handleOnInput: function (ev) {
var data =this.state.AppValue;
data.push(ev);
this.setState({AppValue:data})
console.log(data)
},
});
ReactDOM.render(
<App />,
document.getElementById('content')
);
//如何动态加载出li 现在只能加载出数据
经过中午的仔细推敲问题已经解决 再次感谢两位朋友的帮助
以下是代码
var CommentInput = React.createClass({
})
var CommentListDoingChildren = React.createClass({
});
var App = React.createClass({
});
ReactDOM.render(
);