I have an object with JSON like string which is returned by a function tableToJson(). This is what it looks like.
{
{"Item Code":"sthing","Product Name":"sthing","Qantity":"1","Unit Price":"0","Item Total":"0"},
{"Item Code":"sthing","Product Name":"sthing","Qantity":"1","Unit Price":"0","Item Total":"0"},
{"Item Code":"sthing","Product Name":"sthing","Qantity":"1","Unit Price":"0","Item Total":"0"},
{"Item Code":"sthing","Product Name":"sthing","Qantity":"1","Unit Price":"0","Item Total":"0"}
}
How to save this on firebase database. I am already saving some data above it with JS looks like this:
var databaseRef = firebase.database().ref('Bills');
function submitData(e){
e.preventDefault();
//variables for getting all values
var receiptDate = document.getElementById('date').innerHTML;
var receiptTime = document.getElementById('time').innerHTML;
var receiptBillNo = getInputValues('billNo');
var receiptCompName = getInputValues('companyName');
var receiptEmail = getInputValues('email');
var receiptPhone = getInputValues('phone');
var discount = getInputValues('Discount');
var total = getInputValues('sumTotal');
var newDataref = databaseRef.push();
var itemsJson = tableToJson();//THIS WILL RETURN THE ABOVE JSON STRING
//itemsJson = tableToJson();
//JSON.parse(itemsJson);
newDataref.set({
date: receiptDate,
time: receiptTime,
billNo: receiptBillNo,
company: receiptCompName,
email: receiptEmail,
phone: receiptPhone,
discount: discount,
total:total,
zitems: itemsJson
});
}

Have look at my tableToJson()
function tableToJson(){
var tableId = document.getElementById('dataEntryTable');
var headName;
var headers = [];
var dataArray = [];
var rowCount = tableId.rows.length;
var colCount = tableId.rows[0].cells.length;
dataArray.push("[");
for(var i = 1; i < colCount; i++){
headName = tableId.rows[0].cells[i].innerHTML;
headers.push(headName);
}
console.log(headers);
for(var i = 1; i < rowCount; i++){
dataArray.push("\n{");
//FOR FIRST APPROACH:dataArray.push("\n/"" + i + "/" :{");
for(var j = 1; j < colCount; j++){
var currValue = tableId.rows[i].cells[j].childNodes[0].value;
dataArray.push("\"" + headers[j-1] + "\":" + "\"" + currValue +
"\"");
if(j < (colCount - 1)){
dataArray.push(",");
}
}
if( i < (rowCount - 1)){
dataArray.push("},");
}
else{
dataArray.push("}/n");
}
}
dataArray.push("]");
return dataArray.join("");
}
Is something wrong with this code. Even if I parse it to JSON it is sending as string.
THIS WILL RETURN THE ABOVE JSON STRINGmean?