2 回答
TA贡献1818条经验 获得超7个赞
function updateFAQ(e, id) {
setfaqDesc(
faqDesc.map(faq =>
faq.id === id ? { ...faq, [e.target.name]: e.target.value } : faq
)
);
}
这会将目标名称设置为目标值 onChange
TA贡献1811条经验 获得超5个赞
我假设你有一些arrayLst数据,你可以做这样的事情:
function updateFAQ( value, desc ) {
for (var i in arrayLst) {
if (arrayLst[i].value == value) { // i -> index
arrayLst[i].desc = desc; // add whatever you want to do.
}
}
}
或者
//let your array be
let arrayLst = [
{id: 0, name: "Roy"},
{id: 1, name: "John"},
{id: 2, name: "Doe"},
{id: 3, name: "Angela"}
],
//Find index of specific object using findIndex method.
index= arrayLst.findIndex((obj => obj.id == 1));
console.log("Before update: ", arrayLst[index])
arrayLst[index].name = "Paul" //John to Paul
console.log("After update: ", arrayLst[index])
添加回答
举报