简体   繁体   English

从 object 的拼接数组中更新数据

[英]Update the data from spliced array of object

So, I have splice the data and I want to update it's object from disabled = true to disabled = false .. I have looking for another answer and cant find one..所以,我已经拼接了数据,我想将它的 object 从disabled = true更新为disabled = false .. 我一直在寻找另一个答案,但找不到..

Any Advice is appreciated.任何建议表示赞赏。 Thank you谢谢

this is my dropdown这是我的下拉菜单

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" },
];

selected function: when selected the dropdown, it will add new attribute disabled:true选择 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,
    });
  }

delete function: this is onClick function, when clicked, it should splice the data, and check, if the spliced data have disabled === true change it to disabled:false .删除function disabled:false这是onClick function,点击时应该拼接数据,并检查是否禁用拼接数据disabled === true the spliced have working properly, but not change the attribute to disabled = false拼接的工作正常,但没有将属性更改为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 });
  }

Your splice function not returning the element.您的splice function 没有返回元素。 You may need to change it to您可能需要将其更改为


 selected.splice(index, 1).map((e) => {
     e.disabled === true ? false:true
     return e; 
 })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM