【问题标题】:lodash Type Error has no function findKey()lodash 类型错误没有函数 findKey()
【发布时间】:2015-02-04 08:39:24
【问题描述】:

我是 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:在事件处理程序中检测到错误[39m [TypeError:

对象函数 (obj) { if (obj instanceof _) return obj;

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

this._wrapped = obj; } 没有方法 'findKey'] TypeError: Object 函数 (obj) {

if (obj instanceof _) return obj;

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

this._wrapped = obj; } 没有方法'findKey'

【问题讨论】:

  • 确定_ 变量中有lodash?

标签: javascript node.js lodash


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-08-08
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多