优化代码 const {businessType, certType, certNo, longTude, uploadZqFlag} = this.defaults businessType.editDisplay = true businessType.viewDisplay = true certType.editDisplay = true certType.viewDisplay = true certNo.editDisplay = true certNo.viewDisplay = true longTude.editDisplay = true longTude.viewDisplay = true uploadZqFlag.viewDisplay = true
时间: 2024-04-13 20:30:20 浏览: 185
您可以优化这段代码,将重复的赋值操作合并为一个简洁的写法。以下是优化后的代码示例:
```javascript
const {businessType, certType, certNo, longTude, uploadZqFlag} = this.defaults;
[businessType, certType, certNo, longTude, uploadZqFlag].forEach((item) => {
item.editDisplay = true;
item.viewDisplay = true;
});
uploadZqFlag.viewDisplay = true;
```
通过使用 `forEach` 循环遍历对象属性的数组,您可以一次性设置 `editDisplay` 和 `viewDisplay` 属性为 `true`。最后,您可以单独设置 `uploadZqFlag.viewDisplay` 属性为 `true`。这样,您就能够使用更简洁的代码实现相同的功能。
阅读全文