我的表结构如下:
<table>
<tr class="selected"><th>number</th><td><input type="number"/></td></tr>
<tr><th>name</th><td><input type="text"/></td></tr> ...
</table>
我创建了textarea并选择使用reactjs来相应地更改th
和td
。
代码:
var MySelect = React.createClass({
getInitialState: function() {
return {
value: '',
label: ''
}
},
change: function(event){
this.setState({value: event.target.value});
},
textChange:function(event){
this.setState({label: event.target.value});
},
render: function(){
if($('.selected').length >0 && $('.selected').find('td').length>0){ var stateValue = {this}; $('.selected').find('th')[0].innerHTML = stateValue.this.state.label; }
if($('.selected').length >0 && $('.selected').find('td').length>0){ var newTag = <input type={this.state.value}/>; $('.selected').find('td')[0].innerHTML = {newTag} }
return(
<div>
<p>Field label</p>
<textarea rows="3" cols="30" className="inputControl" id="field_name" onChange={this.textChange}></textarea><br />
<br />
<p>Field type</p>
<select className="inputControl" id="field_control" onChange={this.change} value={this.state.value}>
<option value="text">Textbox</option>
<option value="number">Number</option>
<option value="checkbox">Checkbox</option>
<option value="radio">Radio</option>
<option value="textarea">Textarea</option>
<option value="select">Dropdown</option>
<option value="multiple">Multiple Choice</option>
<option value="date">Date</option>
<option value="phone">Phone</option>
<option value="address">Address</option>
<option value="email">Email</option>
</select>
<br />
<br />
<div id="selectOption" style={{display: 'none'}}>
<p>
Choices
</p>
<div className="space">
<input type="text" className="inputControl" /></div>
<div className="space">
<input type="text" className="inputControl" /><span> <i className="fa fa-plus-circle icon add"
title="Add another choice"></i><i className="fa fa-minus-circle icon remove" title="Delete this choice">
</i></span>
</div>
<div className="space">
<input type="text" className="inputControl" />
<span><i className="fa fa-plus-circle icon add" title="Add another choice"></i><i className="fa fa-minus-circle icon remove"
title="Delete this choice"></i></span>
</div>
</div>
<p><input type={this.state.value} /></p>
</div>
);
}
});
textarea有助于更改th
字段并选择更改td
字段。当我从选择选项中选择时,标记将会更改<p><input type={this.state.value} /></p>
,但会显示[OBJECT OBJECT]
在错误行中..我想根据选择的选项中的选择值更改td
。我可以在var newTag = <input type={this.state.value}/>; $('.selected').find('td')[0].innerHTML = {newTag}
中change:
吗?我错过了这个吗?请建议我..
更新 我可以更改值但是当我点击第二个td并再次第一个td然后它显示旧文本..