Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 环回框架中远程方法的默认值_Node.js_Database_Express_Loopbackjs - Fatal编程技术网

Node.js 环回框架中远程方法的默认值

Node.js 环回框架中远程方法的默认值,node.js,database,express,loopbackjs,Node.js,Database,Express,Loopbackjs,在特定model.js文件中编写应用程序逻辑之后,我为该特定模型定义了远程方法,因为我想公开该api,我想接受一些参数,其中一个参数是objecttype,我想为该参数提供默认值 我是这样做的 { arg: 'whereConditionFilter', type: 'object', default: {}, required: true }, 但是我很困惑,这是做这件事的正确方法。你可以使用beforem

在特定model.js文件中编写应用程序逻辑之后,我为该特定模型定义了远程方法,因为我想公开该api,我想接受一些参数,其中一个参数是
object
type,我想为该参数提供默认值

我是这样做的

     {
        arg: 'whereConditionFilter',
        type: 'object',
        default: {},
        required: true
      },

但是我很困惑,这是做这件事的正确方法。

你可以使用beforemote钩子

Model.beforeRemote('yourCustomRemoteMethod',函数(ctx,instance,next){
设whereConditionFilter=ctx.req.params.whereConditionFilter;
/*在此处修改您的whereConditionFilter并放弃它*/

})
用于填充环回浏览器输入字段和swagger文档的默认值。注意:若参数不存在,此值将不会传递到远程方法函数中。