js用if判断一个空对象为什么会为true?
js用if判断一个空对象为什么会为true?
if ([]) {
console.log("true") //true
}
if ({}) {
console.log("true") //true
}
if ([] == false) {
console.log("true")
}
if ({} == false) {
console.log("true") //true
}
这个需求就是新增/编辑,有值的话,调取详情接口
为什么之前这样不走详情方法,突然今天反馈编辑编辑不了,离了大谱,找半天报错没找到,最后一点一点debug,吗的,新增传的空对象,竟然走进去了。。。
之前正常,就无语,。。
this.$nextTick(() => {
if (row) {
this.dataForm.id = row.id
this.getDatali(row.id)
}
})
改进
this.$nextTick(() => {
// this.$refs.dataForm.resetFields();
console.log(row.id)
if (row.id) {
this.dataForm.id = row.id
this.getDatali(row.id)
}
})
气死