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

252
Vistas
How to dynamically create an expression using javascript and alpine.js

I'm trying to create a conditional menu in a datatable. For some records the menu will appear, in other cases it will not. My backend (PHP) sends the following parameters to the frontend:

['field' => 'blocked_at', 'operator' => '!==', 'value' => null]

or

['field' => 'blocked_at', 'operator' => '===', 'value' => null]

So in HTML I call the function

<template x-if="checkConditions(record[action.conditions.field], action.conditions.operator, action.conditions.value)">
 <a href="#!" class="dropdown-item" x-on:click="runAction(action, record[action.keyfield])">
  <i x-bind:class="action.icon"></i><span x-text="action.label"></span>
 </a>
</template>

function in Alpine.js

checkConditions (field, operator, value) {
 let condition = `${field} ${operator} ${value} ? true : false`;
 return eval(condition);
},

But it doesn't work, I'm getting the error "identifier starts immediately after numeric literal". I don't know why this happens. There is an error in the checkConditions function.

Could you help me solve this challenge?

about 4 years ago · Juan Pablo Isaza
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