I have data coming in json format like this
{
feild: ...
...
"transport_details": [
{
"allotment_id": ObjectId("5b755710d2ccda0978005d6e"),
"status": "Active"
},
{
"allotment_id": ObjectId("5b755710d2ccda0978005d6e"),
"status": "Inactive"
}
]
}
I have written below java script function like
function checkIfInActive(transportAllotment, id)
{
if (transportAllotment.length == 0)
{
return '<div class="checkbox checkbox-success">' +
'<input class="commoncheckbox" type="checkbox" id="studentId_-' + id + '' +
'" name="studentId_-' + id + '" value="' + id+ '"' +' >' + '<label></label></div>';
}
else
{
var max = transportAllotment.length-1;
var status = transportAllotment[max]["status"];
if(status != "Active")
{
return '<div class="checkbox checkbox-success">' +
'<input class="commoncheckbox" type="checkbox" id="studentId_-' + id + '' +
'" name="studentId_-' + id + '" value="' + id+ '"' +' >' + '<label></label></div>';
}
else
{
return '<div class="checkbox"><input class="disabled-check" type="checkbox" disabled><label></label></div>';
}
}
}
I am trying to return html with class commoncheckbox , if the status of last element of sub array transport_details is Inactive. The above is not returning checkbox with class commoncheckbox in such cases.
Please help!!!
checkedattribute to the checbox you want to enable