大佬教程收集整理的这篇文章主要介绍了javascript – React JS:如何从this.state.data中正确删除一个项目,其中数据是一组对象,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
目前,由于包含的对象是ref,即使我做了一个数组的副本,我的表也删除了最后一行(即使在AJAX调用中行索引和数据都被正确引用和删除).
handleRowdelete: function(rowIdX) { // Correct row var row = this.state.data[rowIdx]; // This makes a new array,but the contained objects are still by ref var rows = this.state.data.slice(); // This contains the proper row that will be deleted. If this array is set to data,the table is updated to reflect just the one row - as expected. var throwout = rows.splice(rowIdx,1); console.log(throwout); // Whether I set via the React.addons: var newState = React.addons.update(this.state,{ data: { $set: rows } }); this.setState(newStatE); // Or just set the state again via this.setState(...) //this.setState({data: rows,add: falsE}); // It always just removes the last row in the component render // Even though the proper row gets deleted following in AJAX call $.ajax({ ... },...
我理解React不能做出正确的差异,所以渲染没有被触发,所以你能告诉我应该如何处理?
updatE.相关循环:
var Grid = React.createClass({ propTypes: { data: React.PropTypes.array.isrequired,onCellChange: React.PropTypes.func.isrequired,onRowCommit: React.PropTypes.func.isrequired },render: function() { var rows = this.props.data.map(function(rowData,indeX) { return <Row key={index} data={rowData} onCellChange={this.props.onCellChange.bind(null,indeX)} onRowCommit={this.props.onRowCommit.bind(null,indeX)} onRowdelete={this.props.onRowdelete.bind(null,indeX)} />; },this); return ( <Table Striped bordered hover responsive> <thead> <tr> <th className="col-sm-4">Order Sub@R_561_10586@l (up to)</th> <th className="col-sm-2">Canada</th> <th className="col-sm-2">US</th> <th className="col-sm-2">International</th> <th className="col-sm-1"></th> </tr> </thead> <tbody> {rows} </tbody> </Table> ); } });
以上是大佬教程为你收集整理的javascript – React JS:如何从this.state.data中正确删除一个项目,其中数据是一组对象全部内容,希望文章能够帮你解决javascript – React JS:如何从this.state.data中正确删除一个项目,其中数据是一组对象所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。