首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果在响应期间不是函数,则使用TypeError seneca索引

如果在响应期间不是函数,则使用TypeError seneca索引
EN

Stack Overflow用户
提问于 2017-01-27 20:29:22
回答 1查看 71关注 0票数 0

我已经写了一个简单的操作,使用seneca-mongo store模块连接到mongo db,执行列表查询并获得结果。我可以看到查询是成功的,并且获取了正确的结果。当我尝试将这些结果发送回客户端时,respond调用出现错误,并显示以下消息和堆栈跟踪。

代码语言:javascript
复制
ERROR       act     root$           OUT             cmd:getparams,role:diff 11      {cmd:getparams,role:diff,payload:{id:scalaScan}}    ENTRY    (dqk22) -       seneca: Action cmd:getparams,role:diff callback threw: k.indexOf is not a function.     act_callback    {message:k.indexOf is not a function,pattern:cmd:getparams,role:diff,instance:Seneca/0.7.2/d0twcki9cmxg/1485517      TypeError: k.indexOf is not a function
    at /scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:851:13
    at Function.forEach (/scratch/DiffAnalyzer/node_modules/lodash/dist/lodash.js:3298:15)
    at Object.defaultmodify [as modify] (/scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:850:7)
    at respond (/scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:654:22)
    at Seneca.<anonymous> (/scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:401:7)
    at act_done (/scratch/DiffAnalyzer/node_modules/seneca/seneca.js:1554:16)
    at /scratch/DiffAnalyzer/node_modules/gate-executor/gate-executor.js:127:20
    at Seneca.<anonymous> (/scratch/DiffAnalyzer/analyze.js:613:5)
    at act_done (/scratch/DiffAnalyzer/node_modules/seneca/seneca.js:1554:16)
    at /scratch/DiffAnalyzer/node_modules/gate-executor/gate-executor.js:127:20
    at /scratch/DiffAnalyzer/node_modules/seneca-mongo-store/mongo-store.js:329:21
    at /scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:271:33
    at /scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:778:35
    at Cursor.close (/scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:1009:5)
    at Cursor.nextObject (/scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:778:17)
    at Cursor.each (/scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:264:12)

我所写的动作是

代码语言:javascript
复制
seneca.add("role:diff,cmd:getparams", function(msg, respond) {
    seneca.ready(function() {
        var collection = seneca.make$("paramStore");
        var f = msg.payload;

        seneca.log.info("Filter", f);
        collection.list$(f, function(err, ob) {
            if (err) {
                seneca.log.error(err);
                respond(err);
            } else {
                seneca.log.info("Result", ob);
                respond(null, ob);
            }
        });
    });
});

同样的代码是有效的,现在我得到了这个错误。不确定是什么改变了。任何帮助/建议都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-09 20:36:40

我所面临的问题是因为模块的js文件中的这段代码

代码语言:javascript
复制
if( _.isObject( result.out ) ) {
    _.each(result.out,function(v,k){
      if(~k.indexOf('$') && 'http$' !== k) {
        delete result.out[k]
      }
    })

_.each函数用于解析JSON对象,在我的例子中,输出实际上是一个JSON数组。将数组包装到一个对象中解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41894039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档