Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
si no se dispara dentro de la matriz de objetos

La matriz de objetos no ejecuta el "si" cuando llama a un método con forEach, pero cuando muevo el si dentro de forEach funciona, estoy tratando de averiguar por qué no se activa el si dentro del objeto cuando ejecuta el forEach.

Hay una var (responseFlag) con el valor predeterminado (falso), por lo que si necesita cambiar el procesamiento html, simplemente cámbielo (verdadero/falso) cuando se haga clic en el botón.

 var responseFlag = false, targetRender = document.getElementById('targethtml'), templateTrue = '<h2>true</h2>', templateFalse = '<h2>false</h2>'; // objDef = { "objDefs" : [ { "UIhtml": responseFlag == true ? templateTrue : templateFalse // does not works // "UIhtml": responseFlag // this works } ] }; // UI_exc = { outputResult: function() { objDef.objDefs.forEach(function(key, value){ targetRender.innerHTML = // responseFlag == true ? templateTrue : templateFalse // this works key.UIhtml // does not works console.log(responseFlag) }); }, clickAction: function() { document.getElementById('goRender').addEventListener("click", function(){ responseFlag = true // console.log(responseFlag); UI_exc.outputResult() }); } }; UI_exc.clickAction();
 <button id="goRender">Click</button> <div id="targethtml">[ N ]</div>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Supongo que el problema es que el objeto se inicializa y la propiedad UIhtml se asigna allí, creo que debería cambiar UIhtml a una función y luego llamarlo:

 ... = key.UIhtml() console.log(responseFlag)
about 4 years ago · Juan Pablo Isaza Report

0

Al crear objetos literales, las propiedades declaradas no son una cadena, sino una referencia a algún valor, por ejemplo, cadenas, números, valores booleanos, objetos...

Cambie "UIhtml" a UIhtml.

Lea esta documentación para obtener más información: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!