1
我正在使用下面的代碼...但是如果狀態爲空的iss顯示下面的結果數據庫中...我想刪除如果狀態爲空..如何刪除{}中的空字段.. nodejs
1地址{},狀態{}保存在數據庫中。
function CheckStatus(oldJob, newJob) {
var obj = {};
if(newJob && newJob.Status) {
obj.Status= {};
if (oldJob.Status.total !== newJob.Status.total) {
obj.Status.total = newJob.Status.total;
}
if (oldJob.Status.charge_description && oldJob.Status.charge_description !== newJob.Status.charge_description) {
obj.Status.charge_description = newJob.Status.charge_description;
}
}
}
MongoDB的
"Job" : {
"_id" : ObjectId("5873b352e7621d08fccc5890"),
"updated_by" : "",
"details" : "{\"current_status\":\"Completed\",\"address\":{},\"Status\":{}}",
"changetype" : "Update",
"datetime" : ISODate("2017-01-09T15:59:14.202Z")
},
請幫什麼If條件是如何進入(下面的代碼不工作)
if(obj.address = '{}')
{
console.log('Empty');
}
我改變了我的代碼.. if(obj.address ='undefined')不工作 –
您是否閱讀過我引用的問題?我只回答了「刪除」一個變量的部分。另外,你應該檢查沒有引號的未定義。你永遠不會用一個等號進行比較。 –
if(obj.address == undefined)not working when when if(obj.address = undefined)..這個工作只是空的。 –