2 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個贊
function updateFAQ(e, id) {
setfaqDesc(
faqDesc.map(faq =>
faq.id === id ? { ...faq, [e.target.name]: e.target.value } : faq
)
);
}
這會將目標(biāo)名稱設(shè)置為目標(biāo)值 onChange

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個贊
我假設(shè)你有一些arrayLst數(shù)據(jù),你可以做這樣的事情:
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])
添加回答
舉報(bào)