【问题标题】:How to have a dynamic query field in where clause如何在where子句中有一个动态查询字段
【发布时间】:2019-02-05 00:14:38
【问题描述】:
   function check_model_owner(field, value, callback) { 
      Model.find({where: {field: value }}, function(err, models) {
            //code
         });
    }

这段代码是从两个不同的地方调用的,接下来的两个调用都是一样的。

当然这会中断,因为 field,在 where 子句中,实际上不存在于模型中,应该用函数参数中的 field 变量替换....我可以这样做吗?

【问题讨论】:

    标签: javascript loopback


    【解决方案1】:

    您可以创建查询对象:

    function check_model_owner(field, value, callback) { 
      var query = {};
      query[field] = value;
      Model.find({where: query}, function(err, models) {
    
      });
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-30
      • 2016-02-27
      • 2019-08-27
      • 2022-12-01
      • 1970-01-01
      相关资源
      最近更新 更多