var data={a:1,b:2,c:9,d:4,e:5};
console.log(Object.keys(data));//["a", "b", "c", "d", "e"]
Object.keys(data).map((key,item)=>{
console.log(key,data[key]);//key=>属性名 data[key]=>属性值
});
下面代码示例是再新增的时候清除我定义的对象里的值(可以看到对象属性太多了):
//商品库接口
interface goodsinfo {
goodsId: any
tenantId: any
goodsName: any
shortName: any
secondId: any
pinyin: any
catId: any
brandId: any
barcode: any
unitId: any
unitName: any
bigBarcode: any
bigUnitId: any
bigUnitName: any
unitRate: any
wholesalePrice: any
salePrice: any
status: any
shelfLife: any
origin: any
grade: any
weight: any
size: any
isTobacco: any
tags: any
sort: any
keywords: any
albumPics: any
detailDesc: any
detailHtml: any
detailMobileHtml: any
sourceType: any
revision: any
crtBy: any
crtTime: any
uptBy: any
uptTime: any
}
const goodsInfoModel = ref<goodsinfo>({
goodsId: '',
tenantId: '',
goodsName: '',
shortName: '',
secondId: '',
pinyin: '',
catId: '',
brandId: '',
barcode: '',
unitId: '',
unitName: '',
bigBarcode: '',
bigUnitId: '',
bigUnitName: '',
unitRate: '',
wholesalePrice: '',
salePrice: '',
status: '',
shelfLife: '',
origin: '',
grade: '',
weight: '',
size: '',
isTobacco: '',
tags: '',
sort: '',
keywords: '',
albumPics: '',
detailDesc: '',
detailHtml: '',
detailMobileHtml: '',
sourceType: '',
revision: '',
crtBy: '',
crtTime: '',
uptBy: '',
uptTime: '',
})
//新增数据
function onAddItem() {
// dialogTitle.value = 'add'
Object.keys(goodsInfoModel.value).forEach(key => (goodsInfoModel.value[key] = ''));
insertDialog.value.receive('add', goodsInfoModel.value)
insertDialog.value?.onConfirm()
}