Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
Sequelize / Vue / Node - I'd like to use a query to filter data after it has been returned to my view

I have a table that tracks all user responses to a quiz. This query will successfully get all the data from that table and put it into my TotalQuizResponses array which I then use in my view:

this.totalQuizResponses = ((await QuizResponsesService.index()).data)

However, I'd also like to display the total number of matches in my view. I know this SQL query successfully gets that total number of matches from the table data:

SELECT count(*)
FROM QuizResponses A, QuizResponses B
WHERE A.answerKey = B.answerKey AND A.QuizId = B.QuizId AND A.UserId < B.UserId

I don't want to have to do another service call just to get the count on filtered data that I already have inside my view. Is there a way to somehow filter the data from within the view? I'm unsure how to replicate this logic using pure JavaScript. Thanks for reading.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you need the exact same query on unfiltered data:

countResponses(this.totalQuizResponses);

function countResponses(quizData) {
  let counter = 0;

  for (const quizResponseA of quizData) {
    for (const quizResponseB of quizData) {
      if (quizResponseA === quizResponseB) { continue; }

      const isSameAnswerKey = quizResponseA.answerKey === quicResponseB.answerKey;
      const isSameQuizId = quizResponseA.QuizId === quizResponseB.QuizId;
      const isSameUser = quizResponseA.UserId === quizResponseB.UserId;

      if (isSameAnswerKey && isSameQuizzId && isSameUser) {
        counter++;
      }
    }
  }

  return counter;
}

If you already filtered your data with the same query, this.totalQuizResponses.length is the same as a counter for all the data you have locally

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda