当前位置:网站首页>小程序判断数据为不为空
小程序判断数据为不为空
2022-06-29 15:27:00 【坐等夕阳落time】
说明
主要就是单纯地用if(x),如果x=0,也会是false, 判断为空,所以还要再加一层判断是否为0,为0是不为空。
判断为不为0 js里不能用 == 和 != ,要用 === 和 !==
一 非对象数据的判断
// 非对象模式的判断数据为不为空
export const isDataNotEmpty = function(checkObj) {
console.log(JSON.stringify(checkObj))
let result = false
if (checkObj === 0) {
return true
}
// Checke if it is ""、 undefined、 null 、NaN、 []
if (checkObj) {
return true
}
return false
}
二 对象数据的判断
// 校验表单
verify() {
let isCorrect = true
let obj = this.dataForm
let dataFormTitle = {
spuName: '商品名称',
price: '价格',
barCode: '商品条码',
secondaryArea: '发货地区',
spuLabel: '商品标签',
saleType: '出货类型',
deliveryType: '交付类型',
payType: '付款方式',
storageStatus: '状态',
imagePath: '商品图片'
}
for (var key in obj) {
if (key !== 'barCode' && key !== 'imagePath') {
// 这种会把值为0也判断为空,所以要再判断为不为0
if (!obj[key]) {
if(obj[key] !== 0) {
if(dataFormTitle[key]){
isCorrect = false
uni.showToast({
title: dataFormTitle[key] + '为空',
icon: 'none'
})
return isCorrect
}
}
}
}
}
return isCorrect
},边栏推荐
- MCS: discrete random variable - Hyper geometric distribution
- Unity C basic review 28 - delegation with return (p449)
- .NET程序配置文件操作(ini,cfg,config)
- Create an API rapid development platform, awesome!
- Several imaging modes of polarimetric SAR
- Dynamically listening for DOM element height changes
- kotlin 注解聲明與使用
- . Net program configuration file operation (INI, CFG, config)
- CKS CKA ckad change terminal to remote desktop
- 13.TCP-bite
猜你喜欢

CKS CKA ckad change terminal to remote desktop

Excel中构建SQL语句

Google 软件版本经历周期

stlink故障修复

Knowledge points: what are the know-how of PCB wiring?

13.TCP-bite
![Abnormal logic reasoning problem of Huawei software test written test [2] Huawei hot interview problem](/img/f0/5c2504d51532dcda0ac115f3703384.gif)
Abnormal logic reasoning problem of Huawei software test written test [2] Huawei hot interview problem

数字图像处理复习

数据挖掘复习

分页sql(rownum、row_number、dense_rank、rank)
随机推荐
Lumiprobe deoxyribonucleic acid phosphate CpG 1000 solid carrier
动态监听DOM元素高度变化
Knowledge points: what are the know-how of PCB wiring?
Material dynamic self illumination
stlink故障修复
数据挖掘复习
Unity C basic review 27 - delegation example (p448)
swift JSONSerialization
Introduction to radar related contents
从雷达回波中可获取的信息
MySQL scheduled full database backup & rolling deletion of backup data before the specified date
Lumiprobe reactive dye carboxylic acid: sulfo cyanine7.5 carboxylic acid
适用于遥感图像处理的神经网络
MySQL development specification pdf
Dynamically listening for DOM element height changes
Informatics Olympiad all in one 1002: output the second integer
MCS: discrete random variable Poisson distribution
Development and application of NFT chain Games: Six noteworthy NFT trends in 2022
TDesign, which gave us benefits last time, will tell us its open source story today
GWD:基于高斯Wasserstein距离的旋转目标检测 | ICML 2021