lodash 类型错误 has no function findKey()

lodash Type Error has no function findKey()

我是 node.js-lodash 的新手。目前我想使用这个库的 findKey()-function。不幸的是,我收到类型错误。出了什么问题?

var objCol = {
    'objA' : { 'myattrA' : 'myval1', 'myattrB' : 'myval2' }, 
    'objB' : { 'myattrA' : 'myval3', 'myattrB' : 'myval4' }
};
var obj = _.findKey(objCol, {'myattrA' : 'myval3'});
console.log(obj);

Eclipse Enide中对应的报错信息为:

MessageBuilder : ERROR DETECTED IN event handler[39m [TypeError:

Object function (obj) { if (obj instanceof _) return obj;

if (!(this instanceof _)) return new _(obj);

this._wrapped = obj; } has no method 'findKey'] TypeError: Object function (obj) {

if (obj instanceof _) return obj;

if (!(this instanceof _)) return new _(obj);

this._wrapped = obj; } has no method 'findKey'

原因是 OP 忘记将库加载到 _ 变量。

谢谢基里尔,你是对的,我忘记了开头的这一行:

var _ = require('./../node_modules/lodash');