【发布时间】:2016-05-21 08:29:48
【问题描述】:
我有一个问题,当我将两个对象类型作为远程方法参数传递时,第一个参数被第二个参数覆盖。下面是代码和结果。我怎么能不让第二个参数不覆盖第一个参数?
module.exports = (Model) => {
Model.calculate = (primary, secondary) => {
console.log(JSON.stringify(primary, null, 2));
console.log(JSON.stringify(secondary, null, 2));
return new Promise((resolve, reject) => {
resolve({ Model: calculator.calculate() });
});
};
Model.remoteMethod('calculate', {
accepts: [
{ arg: 'primary', type: 'object', http: { source: 'body' } },
{ arg: 'secondary', type: 'object', http: { source: 'body' } }
],
returns: {arg: 'Result', type: 'string'}
});
};
当我传入主要参数时 { “姓名”:“汤姆” } 和次要参数 { “姓名:“乔” } 在控制台记录主要和次要的 JSON 对象后,我得到了结果。
primary
{
"name": "Joe" <--- WHY?!
}
secondary
{
"name: "Joe"
}
如您所见,Tom 被 Joe 覆盖。
【问题讨论】:
标签: object arguments loopbackjs overwrite strongloop