如何在ReactJs中呈现选定选项的更改表
How to render a Table onChange of a select Option IN ReactJs
我有一个类似的选择选项代码
var SelectOption = React.createClass({
getInitialState: function() {
return {
data: [],
empid: null
};
},
componentDidMount: function() {
//this.loadOptionfromServer();
//setInterval(this.loadCommentsFromServer, this.props.pollInterval);
},
onChange: function(e) {
var employeeId = e.target.value;
if (employeeId == 1) {
this.setState({
empid: 'xxx'
});
} else {
this.setState({
empid: employeeId
})
}
this.renderTable();
},
renderTable: function() {
< Tableforbasictask data = {
data
}
/>
},
render: function() {
return ( < div >
< div >
< h3 > Select Employee to Review < /h3> < SelectOptionList onChange = {
this.onChange
}
data = {
this.state.data
}
/> < /div> {
this.renderTable()
} < /div>
);
}
});
var SelectOptionList = React.createClass({
getInitialState: function() {
return {
empid: ''
};
},
render: function() {
return ( < select id = "select1"
className = "form-control"
data - placeholder = "Basic Select2 Box"
onChange = {
this.props.onChange
} > < option value = "1" > Select Employee < /option> < option value = "2" > Some Value < /option><option value="3">Some Value</option > < option value = "4" > Some Value < /option></select >
);
}
});
ReactDOM.render( < div className = "row" > < SelectOption / > < /div > , document.getElementById('content'));
然后我有一个表组件
var data = [{
id: 1,
taskName: "Pete Hunt",
standarDescription: "This is one comment",
emplComment: "meaaow I am meeawo",
empRating: "1"
}, {
id: 2,
taskName: "Pete Hunt",
standarDescription: "This is one comment",
emplComment: "meaaow I am meeawo",
empRating: "1"
}, {
id: 3,
taskName: "Pete Hunt",
standarDescription: "This is one comment",
emplComment: "meaaow I am meeawo",
empRating: "1"
}, {
id: 4,
taskName: "Pete Hunt",
standarDescription: "This is one comment",
emplComment: "meaaow I am meeawo",
empRating: "1"
}, {
id: 5,
taskName: "Pete Hunt",
standarDescription: "This is one comment",
emplComment: "meaaow I am meeawo",
empRating: "1"
}];
var Addcontenttotable = React.createClass({
render: function() {
return ( < tr > < td > {
this.props.taskName
} < /td> < td > {
this.props.standarDescription
} < /td> < td > {
this.props.emplComment
} < /td> < td > {
this.props.empRating
} < /td> < /tr > );
}
});
var TableforbasictaskList = React.createClass({
render: function() {
var commentNodes = this.props.data.map(function(comment) {
return ( < Addcontenttotable taskName = {
comment.taskName
}
standarDescription = {
comment.standarDescription
}
emplComment = {
comment.emplComment
}
empRating = {
comment.empRating
}
key = {
comment.id
} >
< /Addcontenttotable>
);
});
return ( < tbody > {
commentNodes
} < /tbody>);
}
});
var Tableforbasictask = React.createClass({
getInitialState: function() {
return {
data: this.props.data
};
},
handleSubmit: function(comment) {
comment.id = this.state.data.length + 1;
this.setState({
data: this.state.data.concat(comment)
});
},
render: function() {
return ( < div className = "downloadlinks" >
< table className = "table table-bordered table-striped-col nomargin"
id = "table-data" >
< thead >
< tr align = "center" >
< td > Task Name < /td> < td > Standard Discription of Task < /td > < td > Employee Comment < /td> < td > Employee rating < /td > < /tr> < /thead >
< TableforbasictaskList data = {
this.state.data
}
/> < /table >
< /div>
);
}
});
只有当"选择标记"中的"选项"发生更改时,我才尝试渲染表。
但这并没有发生
这是链接到小提琴
首先,我没有得到你想要做什么的要点,但可以肯定的是,你的功能:
renderTable: function() {
<Tableforbasictask data = {data}/>
}
需要返回组件,所以应该是这样的:
renderTable: function() {
return <Tableforbasictask data = {data}/>
}
另外,在onChange
事件中,您调用renderTable
(不需要这样做),setState
将自动调用将调用renderTable
的组件的render
方法。
相关文章:
- 我的单元测试选项是什么
- 如何更改bigquery API中的计费层选项
- 如何在ReactJS JSX中执行嵌套的if-else语句
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- 使用Javascript获取所选选项ID
- Selectize.js:如何对整数值的选项进行排序
- 通过js在新选项卡中有条件地打开url
- 按照选项卡索引的顺序循环一个jQuery选择
- ReactJS映射:如何仅在url变量不为空时呈现html链接
- 如何在使用selectBoxIt JQuery插件时检测选项更改
- 如何更改reactjs中外部/独立组件的状态或属性
- 无法在Ionic select中预先选择最后一个选项
- 如何在选项卡上定义属性'的主窗口对象
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 使用此选项选择父类内部的类
- CKeditor:更改对话框中的默认选择选项
- JQuery覆盖不更改单选选项
- 如何在ReactJs中呈现选定选项的更改表
- ReactJS:如何识别浏览器选项卡是否已关闭
- ReactJS和Meteor:生成