在嵌套对象中查找键

时间:2016-02-26 14:58:06

标签: javascript arrays object lodash

为什么这总是返回false?

var dependsOn = {
  "Cadastro": {
    "RHID": "RHID"
  },
  "Agregados": {
    "CD_DOC": "CD_DOC"
  },
  "Documentos": {
    "RHID": "CD_DOC"
  }
}
var field = 'RHID'

_.mapKeys(dependsOn, function(value, key) {
  if (_.some(dependsOn[key], function(o) {
      return _.has(o, field);
    })) {
    console.log(key);
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>

1 个答案:

答案 0 :(得分:0)

_.findKey(dependsOn, field); //