Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda