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

162
Views
Necesito ocultar el valor nulo de la salida para la cuadrícula flexible de mis productos

Necesito mostrar productos en varias categorías en el sitio web de mi empresa, pero a veces un valor será nulo. Me gustaría mostrar nada para esas situaciones, pero no tengo idea de cómo hacerlo.

Cualquier ayuda sería apreciada.

No puedo compartir el punto final, aceptar o autorizar, por lo tanto, el extraño texto "va aquí" en el código:

 var settings = {
 "url": " 'API endpoint goes here' ",
 "method": "GET",
 "timeout": 0,
 "headers": {
 "accept": " 'JSON goes here' ",
 "Authorization": " 'authorization key goes here' "
 },
};

$.ajax(settings).done(function(response) {
 console.log(response);

 $.each(response.data, function(index, value) {
 console.log(value);

 var name = value.name;
 var productNumber = value.productNumber;
 var size = value.size;
 var photo = value.primaryPhoto.standard;
 var id = value.id;

 $('.output').append('<div class="single-product"><div class="photo"><img src="' + photo + '" alt="product bag"/></div><h5 class="name">' + name + '</h5><p class="productNumber">' + productNumber + '</p><p class="size">' + size + '</p><a href="https://productpage.co/product-single/?id=' + id + '"><div class="button" style="text-align: center; font-weight: bold; color: white;">LEARN MORE</div></a></div>');
 })
});
almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

puede usar return para saltar a la siguiente iteración cuando el value es nulo o si desea romper completamente el ciclo, puede usar return false;

 $.each(response.data, function(index, value) {
 console.log(value);

 //skip to next iteration/product when there's no data in value
 if (value == null) {
 return;
 }

 var name = value.name;
 var productNumber = value.productNumber;
 var size = value.size;
 var photo = value.primaryPhoto.standard;
 var id = value.id;

 $('.output').append('<div class="single-product"><div class="photo"><img src="' + photo + '" alt="product bag"/></div><h5 class="name">' + name + '</h5><p class="productNumber">' + productNumber + '</p><p class="size">' + size + '</p><a href="https://backyardboost.co/product-single/?id=' + id + '"><div class="button" style="text-align: center; font-weight: bold; color: white;">LEARN MORE</div></a></div>');
})
almost 4 years ago · Santiago Trujillo 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!