A
A
Alex102142021-08-23 13:54:27
Node.js
Alex10214, 2021-08-23 13:54:27

How to filter by array?

Hello, I have such a problem. An array of strings comes to me:
[ 'TMNG', 'SA' ]
In the database, I have a column conditionally "short_name". I need to return data that has either "TMNG" or "SA" in this column. Here is my code:

const getSystemsForStatisticsPage = require('../models/Allocation');

module.exports.getSystemsForStatisticsPage = async (req, res) => {
  console.log(req.body.el) <---  [ 'TMNG', 'SA' ]
  if (req.body.el !== null) {
    try {
      const arr = await getSystemsForStatisticsPage.findAll({
        where: {
          short_name: req.body.el,
        }
      })
      res.status(201).json(arr);
    } catch (e) {
      console.log(e)
      res.status(500).json({
        message: 'Server ERROR!'
      })
    }
  } else {
    res.status(201).json([]);
  }
}

Tell me what I'm doing wrong and how to do it right. I am using Sequelize.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maddog670, 2014-06-20
@Andreii787

jsfiddle.net/BE8qT/1

Y
Yuri Lobanov, 2014-06-20
@iiil

Most likely from a space character between inline-block elements.
If you have two divs that have display:inline-block, then try to arrange them in the code like this:
or like this

<div>...</div><!--
--><div>...</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question