react table里跳转页面_在reactjs中单击时在表行上添加编辑字段,而无需使用react-table库...

How to change a particular row that is clicked in JSX table to change to input editable row without using any libraries such as react-table?

NameAgeClassSection

{this.setState({clientIsEditing:true},this.edit(key,item))}}>

{item[1]}{item[2]}{item[3]}{item[4]}})}

the above is the code to display table. this.state.students has the student details from db. I want the particular table row to be changed to a row of input fields on click. Kindly help. I'm new to the world of react.

解决方案

If I understand your question correctly, it seems like you need to track additional state to determine if a "student" row is currently in editing mode or not. Perhaps you could achieve that by doing something like this:

NameAgeClassSection

{ this.state.students.map((item,key) => {

const editField = (value, index) => {

// Clone students data before mutation

const students = this.state.students.map(item => ({ ...item }))

// Update field by index of current student

students[key][index] = value

// Trigger re-render

this.setState({ students })

}

return (

{

// Clone students data before mutation

const students = this.state.students.map(i => ({ ...i, editing : item.editing && i===item }))

// Toggle editing flag of this current student (ie table row)

students[key].editing = true;

// Trigger re-render

this.setState({

clientIsEditing:true, // This might not be needed ?

students

})

}

}>

{ item.editing ? editField(e.target.value, 1) } /> : {item[1]} }{ item.editing ? editField(e.target.value, 2) } /> : {item[2]} }{ item.editing ? editField(e.target.value, 3) } /> : {item[3]} }{ item.editing ? editField(e.target.value, 4) } /> : {item[4]} } )

})

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值