[英]Difficulty updating state to reflect what's in a spliced updated object array
[英]Update the data from spliced array of object
所以,我已經拼接了數據,我想將它的 object 從disabled = true
更新為disabled = false
.. 我一直在尋找另一個答案,但找不到..
任何建議表示贊賞。 謝謝
這是我的下拉菜單
const newDrop = [
{ key: "1", label: "Monthly GMV", sublabel: "Max.1" },
{ key: "2", label: "AOV", sublabel: "Max.1" },
{ key: "3", label: "Monthly Order", sublabel: "Max.1" },
{ key: "4", label: "Last Purchase", sublabel: "Max.1" },
{ key: "5", label: "Has Purchase" },
{ key: "6", label: "Has Purchase Spesific Product" },
{ key: "7", label: "Located In", sublabel: "Max.1" },
];
選擇 function:選擇下拉列表時,將添加新屬性disabled:true
newInput({ key }) {
const {
changeFormAttribute,
form: { selectedDrop, newDrop, data },
} = this.props;
itemIndex = newDrop.map((itm) => {
let x = itm.key === key;
return x && itm.key !== "6" && itm.key !== "5" ? { ...itm, disabled: true } : { ...itm };
});
changeFormAttribute({
newDrop: itemIndex,
});
}
刪除function disabled:false
這是onClick function,點擊時應該拼接數據,並檢查是否禁用拼接數據disabled === true
拼接的工作正常,但沒有將屬性更改為disabled = false
deleteInput(index) {
const {
changeFormAttribute,
form: { selectedDrop },
} = this.props;
let selected = selectedDrop || [];
selected.splice(index, 1).map((e) => {return e.disabled === true ? false:true })
changeFormAttribute({ selectedDrop: selected });
}
您的splice
function 沒有返回元素。 您可能需要將其更改為
selected.splice(index, 1).map((e) => {
e.disabled === true ? false:true
return e;
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.