You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js函数传参失败求助:无法传递参数,参数为空

解决Node.js函数参数传递为空的问题

嘿,我瞅了你的代码,问题根源就在**getLocation函数的调用方式错误**上,咱们来一步步修正:

问题出在哪?

在getTable函数里,你调用getLocation的写法是这样的:

getLocation(function(link, callback) { 
  // 此代码块尝试传递link作为参数
  console.log(callback); 
});

但getLocation的定义是需要两个参数:第一个是link对象,第二个是回调函数。你现在把一个匿名函数当成第一个参数传进去了,导致getLocation里的link参数拿到的是这个匿名函数(而不是你想要传递的getTable的link参数),自然会看起来“为空”。

修正后的代码

把getTable里的getLocation调用改成下面这样,正确传递link参数和回调函数:

function getTable(link) { 
  var session = obj.createSession(); 
  session.table(id, 20, function(err, table) { 
    // 此代码块执行相关操作
    responseCb(link.id, link.jx, err, table); 
    console.log("extracted."); 
  }); 
  // 修正getLocation的调用:第一个参数传link,第二个传回调函数
  getLocation(link, function(location) { 
    // 这里可以使用getLocation返回的location值
    console.log("拿到的location:", location); 
    console.log("传递过来的link:", link); 
  }); 
}

额外注意点

  • 你代码里的cond.是占位符,记得替换成实际的条件判断逻辑,不然会触发语法错误
  • getLocation里的var location = value;中的value也要替换成实际获取到的位置值,不然回调返回的location会是undefined

这样修改后,getLocation里的console.log(link)就能正确打印出你从getTable传递过来的link对象啦~

内容的提问来源于stack exchange,提问作者bot.top.pop

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:07:34