Kwasi Denkyira

Kwasi Denkyira

  • 1.5k
  • 197
  • 14.8k

Hide or show item using jquery array

Oct 17 2022 8:26 PM

I have an array using MVC Model, which returns values an array of data. I am looping through the array to find out if an item Status is Inactive then want to hide Add Button else if item Status is Active show the Add button. IBelow is my code which  is looping through the array and defaulting to the first item, therefore hiding the Button even if it is Active. Any help will be appreciated.

 

var result = [{"Id":399,"Number":"Test09_05_2022","Name":"Test_10_03_2022","Status":"Inactive"}, {"Id":377,"Number":"000-1","Name":"New", "Status":"Inactive"}, {"Id":386,"Number":"000-8","Name":"NewEmployee", "Status":"Active"}, {"Id":382,"Number":"05 FEB 2020,"Name":"Test","Status":"Active"}] result.forEach(function (e) { var conStatus = e.Status; if (conStatus === "Inactive") { $("#AddButton").hide(); return true; } else (conStatus === "Active") { $("#AddButton").show(); return true; } return true; });

 


Answers (3)