I have a JSON data object which I am retrieving from mongoDB. It has the following format:
var billData = [{
"_id": "PT155/454",
"_class": "com.aventyn.hms.domain.OPDBill",
"billingDate": "2017-11-20",
"patientId": "PT155",
"transactions": [{
"txnId": "PT155/454/1",
"toBePaid": "0",
"txnAmount": "0",
"due": "0",
"selfPay": true
}, {
"txnId": "PT155/454/2",
"toBePaid": "450",
"txnAmount": "350",
"due": "100",
"selfPay": false
}]
}, {
"_id": "PT156/455",
"_class": "com.aventyn.hms.domain.OPDBill",
"billingDate": "2017-11-20",
"patientId": "PT156",
"transactions": [{
"txnId": "PT156/455/1",
"toBePaid": "300",
"txnAmount": "200",
"due": "100",
"selfPay": true
}, {
"txnId": "PT156/455/2",
"toBePaid": "100",
"txnAmount": "50",
"due": "50",
"selfPay": true
}]
}];
My problem is I want to remove those transactions which have property of selfPay: false for this I am doing the following but It is not working:
$.each(billData, function (k, v) {
$.each(v.transactions, function (tK, tV) {
if (tV.selfPay == true) {
billData[k].transactions = tV;
}
});
});
But the data which I get is same as what I am getting from the database.
Any idea how can I achieve this?
Thanks for your Help.
Link for jsfiddle is: https://jsfiddle.net/0uy38pLf/
v.transactionshould bev.transactions, no?