I am trying to add a new item to my firebase database with a specific JSON object structure:
var newItem = {
'address': "Кабанбай батыр, 53",
'cityId': 1,
'courierName': "Максат",
'dispatcherId': "somedispatcherId",
'info': "привезти к 2ому подъезу в 11 ч вечера",
'isCompleted': 0,
'isProceeded': 0,
'name': "Адиль Жалелов" ,
'paymentMethod': "наличка" ,
'phone': "87775634456" ,
'price': 5000,
'products': []
}
The issue I am facing is that I cannot push an array of objects ($scope.orders) to the newItem.
I have attempted to push this $scope.orders:
$scope.addOrder = function(){
var orderRef =
firebase.database().ref().child('Orders').child('Astana');
var newOrderKey = orderRef.push().key;
var newJson = {
'address': "Кабанбай батыр, 53",
'cityId': 1,
'courierName': "Максат",
'dispatcherId': "somedispatcherId",
'info': "привезти к 2ому подъезу в 11 ч вечера",
'isCompleted': 0,
'isProceeded': 0,
'name': "Адиль Жалелов" ,
'paymentMethod': "наличка" ,
'phone': "87775634456" ,
'price': 5000,
'products': []
};
newJson['products'].push( $scope.orders);
/*for (var i =0; i < $scope.orders.length ; i++){
newJson['products'].push( $scope.orders[0]);
} */
console.log($scope.orders,newJson)
orderRef.child(newOrderKey).set(newJson);
}
Unfortunately, I encountered an error: Reference.set failed: First argument contains an invalid key ($$hashKey) in property....
When I log $scope.orders, I get:
https://i.sstatic.net/H5Cib.png
If anyone has any insights or can offer assistance, it would be greatly appreciated!
Thank you in advance!