Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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
Loopbackjs 如何在环回js中动态添加字段?_Loopbackjs_Strongloop - Fatal编程技术网

Loopbackjs 如何在环回js中动态添加字段?

Loopbackjs 如何在环回js中动态添加字段?,loopbackjs,strongloop,Loopbackjs,Strongloop,我的前端查询: {%22where%22:{%22emp_代码%22:%22EMPT01%22} 原始where查询:{“where”:{“emp_代码”:“EMPT01”} 我试图在上述传入请求中动态添加“code”字段 Employee.observe('access', function (ctx, next) { // first way, it is not adding "orgId" field. ctx.query.where = {

我的前端查询:

{%22where%22:{%22emp_代码%22:%22EMPT01%22}

原始where查询:{“where”:{“emp_代码”:“EMPT01”}

我试图在上述传入请求中动态添加“code”字段

Employee.observe('access', function (ctx, next) {
      // first way, it is not adding "orgId" field. 
      ctx.query.where = {
           orgId: ctx.options.data.orgId
      };
      // second way, it is not adding "orgId" field.
      const query = {};
      query['orgId'] = ctx.options.data.orgId;
      ctx.query.where = query;
      next();
  });
请有人引导我,哪里不对

环回版本:3


谢谢,我用这种方法解决了这个问题

Employee.observe('access', function (ctx, next) {
        // instead single , check both condition 
        if(ctx.query.where !=undefined){
            // if the request does not contain **where** then add it & filter it
            ctx.query.where.orgId = ctx.options.data.orgId;
        }else{
             ctx.query.where = {
                 orgId: ctx.options.data.orgId
             };
        }
        next();
  });

get请求中的
ctx.options.data
来自哪里?我已经在没有它的情况下测试了你的代码,它正在工作。另外,您没有添加到查询中,而是将其替换。ctx.options.data:它来自中间件。请尝试发布连接器调试字符串。