JavaScript实用操作

Object.keys(obj) 获得一个对象的所有key并存入数组

JS快速将对象中所有键赋值为空

data(){
     dialogConfig: {
     applyTime: "2022-02-20",
     auditStatus: "1",
     cashBalance: 12.00,
     commissionBalance: 11.00,
     earningsBalance: 12.01,
     groupBuyingOrganizerStatus: 1,
     id: 20,
     phoneNumber: "12322421414",
     receiverAddress: "dodo",
     recommendGroupBuyingOrganizer: "gogo",
     referrer: "aa",
     remark: "huhuhu",
     storeName: "aiaiia",
    }
}
  let obj = this.dialogConfig;
    Object.keys(obj).forEach((key) => {
        obj[key] = "";
  });

JS快速将一个对象的数据传给另外一个对象中

config: {
  thead: [
       { label: "联系方式", prop: "phoneNumber", width: 120 },
       { label: "店铺名称", prop: "storeName", width: 150 },
       { label: "提货地址", prop: "receiverAddress", width: 230 },
          ],
    checkbox: true,
},
 data() {
     return {
        table_config: {
            thead: [],
            checkbox: "",
        },
    };
},
  for (let key in this.config) {
      if (Object.keys(this.table_config).includes(key)) {
            this.table_config[key] = this.config[key];
         }
      }

JS操作数组 filter()返回符合条件的那一行数据

    audit_status: [
        { label: "待审核", value: 1 },
        { label: "审核中", value: 2 },
        { label: "通过", value: 3 },
        { label: "不予通过", value: 4 }
    ]
 const data = this.audit_status.filter(
         (item) => item.value == 1 //假设此时是1,返回的是 { label: "待审核", value: 1 }
     );
 if (data && data.length > 0) {
         return data[0].label;  //获得的是"待审核"
    }
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务