Creating a JSON Object Array
Hi all -
The below solution works. However I'm not sure this is the best approach. Can someone supply a "better" way of creating the json object below (if there is one)? Thank you for any advice you can provide.
- var buildInvItemsObj = function() {
AVDB.transaction(function (tx) {
tx.executeSql("SELECT * FROM invoice_items WHERE invStatus = ?;", [ 'Incomplete' ],
function (tx, results) {
if (results.rows.length > 0) {
var jsonObjItems = [];
for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
jsonObjItems.push({
invoiceRel:row.invRel,
itemsNumber:row.itemNumber,
itemsDesc:row.itemDesc,
itemsRetail:row.itemRetailPrice,
itemsPrice:row.itemPrice,
itemsQty:row.itemQty,
itemsBarcode:row.itemBarcode
});
} // for i
}
items = jsonObjItems;
});
});
return items;
}