0
我有一個對象,我需要檢查一個屬性是否爲null,但總是得到undefined。用lodash查找null屬性
var obj={
"EMPRESA": "CMIP",
"CD_DIRECAO": "01",
"DT_INI_DIRECAO": "1900-01-01",
"CD_DEPT": "10",
"DT_INI_DEPT": "1900-01-01",
"CD_PROC": "1",
"DT_INI_PROC": "1900-01-01",
"DSP_PROC": "Processo 1",
"DSR_PROC": "Processo 1",
"DESCRICAO": null,
"ID_PROCESSO_ARTIGO": null,
"VALIDACAO_ARTIGO": null,
"DT_FIM": null,
"DT_RowId": "row_CMIP011900-01-01101900-01-0111900-01-01",
"DESIGEMPRESA": "CMIP",
"DSP_DIRECAO": "Disponivel",
"DSP_DEPT": "ADM - Administracao"
};
console.log(_.find(obj,{'DT_FIM':null}));
我設置一個小提琴https://jsfiddle.net/0a6yf34b/1/
那麼爲什麼不直接用JavaScript做呢? 'if(obj [「DT_FIM」] === null)' – epascarello
是的,沒關係,但爲什麼我沒有定義。謝謝 –
由於'_.find'需要一個謂詞函數作爲第二個參數,而不是要搜索的鍵值對,所以你會得到'undefined'。而且,如果用在一個對象上,它將搜索_the values_。 – vlaz