I am wondering how can do something like this:
Output I am looking for:
{ item_id0 : 123, quantity0: 99 , item_id1 : 124, quantity1: 50 }
My sample code but not working:
var data = {};
angular.forEach(vm.fields, function(value, key){
data = {
item_id[key] : vm.selectedItem[key].id,
quantity[key] : vm.quantity[key]
}
})
console.log(data);
[{id:123,quantity:99}, {id:124,quantity:50}]) you could probably be better off just doingdata['item_id'+key] = vm.selectedItem[key].id;$http.post('server/add-transaction.php', data).then(function(res){ console.log(res); })@Schorsch, formating is not really important but I think I need it to pass in my php insert query.