element-ui 保存时的思路逻辑整理

存在两种情况:新增和编辑
  • 编辑时,重要的一步是要把传过来的index放到config中,也就是更新
  • 新增时,要判断config.index是否存在,不能直接使用if(this.config.index){}因为当数据里面的第一个数据的index为0时就成了新增了,要使用if(this.config.index!==”)来使用
  • 更重要的一点,数据添加完之后,要恢复数据的默认值,把this.config.index=”,不过有的写成this.$set(this.config, “storeAndPosIndex”, “”);
    //保存新增的门店名称和岗位
    saveStorePost() {
      let { store, position } = this.form;
      let storeAndPosindex = this.config.storeAndPosIndex;
      this.config.showDialog = false;
      let midObj = {};
      for (var k in this.form.position) {
        if (this.form.position[k].selected) {
          midObj.postId = this.form.position[k].postId;
          midObj.postName = this.form.position[k].postName;
        }
      }
      for (var l in this.form.store) {
        if (this.form.store[l].selected) {
          midObj.storeId = this.form.store[l].storeId;
          midObj.storeName = this.form.store[l].storeName;
        }
      }
      //TODO 更新时,不能用index是否有效来判断,当index=0时,会进入新增的if里面,要使用!==''
      if (storeAndPosindex !== "") {
        this.$set(this.form.positionList, storeAndPosindex, midObj);
      } else {
        this.form.positionList.push(midObj);
      }
      //TODO 清空编辑时的index
      this.$set(this.config, "storeAndPosIndex", "");
      //回复默认值- form.position
      for (var p in this.form.position) {
        this.form.position[p].selected = false;
      }
      for (var s in this.form.store) {
        this.form.store[s].selected = false;
      }
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值