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; });
Gowtham RamarPosted Oct 19, 2022, 6:20 AM
Hi ,,
your using else with condition
else (conStatus === "Active")
{
$("#AddButton").show(); return true;
}
change
else if(conStatus === "Active")
if you want without condition use
result.forEach(function (e) {
var conStatus = e.Status; if (conStatus === "Inactive")
{
$("#AddButton").hide(); return true;
}
else
{
$("#AddButton").show(); return true;
}
return true; });
Kwasi DenkyiraPosted Oct 18, 2022, 11:34 AM
Hi Rathar
I copied and paste the same question I am asking so I don't see your answer
result.forEach(function (e) {
var conStatus = e.Status; if (conStatus === "Inactive")
{
$("#AddButton").hide(); return true;
}
else (conStatus === "Active")
{
$("#AddButton").show(); return true;
}
return true; });
I don't see this and your answer.
Gowtham RamarPosted Oct 18, 2022, 10:34 AM
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 if (conStatus === "Active") { $("#AddButton").show(); return true; }
return true;
});