const data = [ { adjustDesc: null, adjustStatus: 0, adjustWorkerPrices: null, backrestMaterialName: "HK001-44", backrestMaterialNo: "02.YCL.BL.SD.HK001-44", basicsMaterialName: "HK001-44", basicsMaterialNo: "02.YCL.BL.SD.HK001-44" createTime :1,updateTime:2}, { adjustDesc: null, adjustStatus: 0, adjustWorkerPrices: null, backrestMaterialName: "HK001-44", backrestMaterialNo: "02.YCL.BL.SD.HK001-44", basicsMaterialName: "HK001-44", basicsMaterialNo: "02.YCL.BL.SD.HK001-44" createTime :1,updateTime:2}, { adjustDesc: null, adjustStatus: 0, adjustWorkerPrices: null, backrestMaterialName: "HK001-44", backrestMaterialNo: "02.YCL.BL.SD.HK001-44", basicsMaterialName: "HK001-44", basicsMaterialNo: "02.YCL.BL.SD.HK001-44" inOutboundList:{afda:11,createTime :1,updateTime:2} ,createTime :1,updateTime:2 } ]; vue中实现 去掉createTime :1,updateTime:2 包扩inOutboundList里面的
时间: 2024-04-19 16:25:52 浏览: 176
要从给定的数据中删除特定的属性,您可以使用 Vue.js 中的 `v-for` 循环来遍历数据,并使用 `v-bind` 指令动态绑定属性。以下是一个示例代码,展示了如何在 Vue.js 中实现您的需求:
```html
<template>
<div>
<div v-for="item in filteredData" :key="item.basicsMaterialNo">
<div v-if="item.inOutboundList">
<div v-bind="item.inOutboundList"></div>
</div>
<div v-else>
<div v-bind="item"></div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
data: [
{
adjustDesc: null,
adjustStatus: 0,
adjustWorkerPrices: null,
backrestMaterialName: "HK001-44",
backrestMaterialNo: "02.YCL.BL.SD.HK001-44",
basicsMaterialName: "HK001-44",
basicsMaterialNo: "02.YCL.BL.SD.HK001-44",
createTime: 1,
updateTime: 2
},
{
adjustDesc: null,
adjustStatus: 0,
adjustWorkerPrices: null,
backrestMaterialName: "HK001-44",
backrestMaterialNo: "02.YCL.BL.SD.HK001-44",
basicsMaterialName: "HK001-44",
basicsMaterialNo: "02.YCL.BL.SD.HK001-44",
createTime: 1,
updateTime: 2
},
{
adjustDesc: null,
adjustStatus: 0,
adjustWorkerPrices: null,
backrestMaterialName: "HK001-44",
backrestMaterialNo: "02.YCL.BL.SD.HK001-44",
basicsMaterialName: "HK001-44",
basicsMaterialNo: "02.YCL.BL.SD.HK001-44",
inOutboundList: {
afda:11,
createTime: 1,
updateTime: 2
},
createTime: 1,
updateTime: 2
}
]
}
},
computed: {
filteredData() {
return this.data.map(item => {
const updatedItem = { ...item }; // Create a shallow copy of the item
// Remove createTime and updateTime properties
delete updatedItem.createTime;
delete updatedItem.updateTime;
// If inOutboundList exists, remove its createTime and updateTime properties
if (updatedItem.inOutboundList) {
delete updatedItem.inOutboundList.createTime;
delete updatedItem.inOutboundList.updateTime;
}
return updatedItem;
});
}
}
}
</script>
```
在上面的代码中,我们使用 `v-for` 循环遍历数据数组,并使用 `v-bind` 指令动态绑定属性。在 `filteredData` 计算属性中,我们创建了每个项的浅拷贝,并删除了指定的属性。如果 `inOutboundList` 存在,则还会删除其内部的 `createTime` 和 `updateTime` 属性。最终,我们渲染更新后的数据。
阅读全文