这可以在一份声明中实现吗?

问题描述 投票:0回答:1
const where = {
  office_no: 1999,
  status: "APPLY",
  [Op.and]: [
    Sequelize.literal(
      `${property_master_no} member of (request_json->'$.property[*].property_master_no')`,
    ),
  ],
};

if (document_no) {
  where["no"] = {
    [Op.not]: document_no,
  };
}

我想在

if
中制作
const where

抱歉。我不知道。

node.js sequelize.js
1个回答
1
投票

通过使用组合扩展和三元运算符确实可以实现

 const where = {
        office_no: 1999,
        status: 'APPLY,
        [Op.and]: [
            Sequelize.literal(`${property_master_no} member of (request_json->'$.property[*].property_master_no')`)
        ],
        ...(document_no ? { 'no': { [Op.not]: document_no } } : {})
    }
© www.soinside.com 2019 - 2024. All rights reserved.