I have a function that builds a data object that I pass to a client side template.
When I pass the data output as text everything works fine, but when I try to pass the results of the javascript it does not work.
I have made a short video to show the problem. After the first minute the video goes black but it has explained everything by that time.
https://www.youtube.com/watch?v=W_q7GvF3wNA
function cart() {
var count = {dialog.Object}._getRepeatingSectionRowCount('CONTAINER_2',true);
var name = "Lunch";
var location = "Central";
var total = 0;
var text = "[";
var res = '';
var i;
for (i = 1; i <= count; i++) {
var Qty = {dialog.object}.getValue('Qty' + ':' + i);
var Desc = {dialog.object}.getValue('Desc' + ':' + i);
var Price = {dialog.object}.getValue('Price' + ':' + i);
text += "{qty: " + Qty + " , " + "desc: '" + Desc + "' , " + "price: " + Price + " , res: '' " + "}," + "<br>";
total = total + parseInt(Price)
}
i = count
var Qty = {dialog.object}.getValue('Qty' + ':' + i);
var Desc = {dialog.object}.getValue('Desc' + ':' + i);
var Price = {dialog.object}.getValue('Price' + ':' + i);
text += "{qty: '' " + " , " + "desc: '" + "<strong> Total</strong>" + "' , " + "price: " + total + " , res: 'style= " + "\" text-align:right\"'" + "}]" ;
var before = "[{meal: '" + name + "', location: '" + location + "', table: "
text = before.concat(text);
text += "}];";
// the following three lines of code are for testing to look at the result.
document.getElementById("demo").innerHTML = text;
var text = document.getElementById("demo").innerHTML ;
document.getElementById("copy").innerHTML = text;
// I have cut and pasted from the div and manually set the obj to the output of text if I don't do this I cannot get it to work.
obj = [{meal: 'Lunch', location: 'Central', table: [{qty: 1 , desc: 'BLT' , price: 50 , res: '' },
{qty: 2 , desc: 'Classic Club' , price: 100 , res: '' },
{qty: 4 , desc: 'Santa Fe' , price: 200 , res: '' },
{qty: 3 , desc: 'Breakfast Special' , price: 150 , res: '' },
{qty: '' , desc: ' Total' , price: 500 , res: 'style= " text-align:right"'}]}];
return obj
}
When I pass the data output as text everything works fine, but when I try to pass the results of the javascript it does not work.
I have made a short video to show the problem. After the first minute the video goes black but it has explained everything by that time.
https://www.youtube.com/watch?v=W_q7GvF3wNA
function cart() {
var count = {dialog.Object}._getRepeatingSectionRowCount('CONTAINER_2',true);
var name = "Lunch";
var location = "Central";
var total = 0;
var text = "[";
var res = '';
var i;
for (i = 1; i <= count; i++) {
var Qty = {dialog.object}.getValue('Qty' + ':' + i);
var Desc = {dialog.object}.getValue('Desc' + ':' + i);
var Price = {dialog.object}.getValue('Price' + ':' + i);
text += "{qty: " + Qty + " , " + "desc: '" + Desc + "' , " + "price: " + Price + " , res: '' " + "}," + "<br>";
total = total + parseInt(Price)
}
i = count
var Qty = {dialog.object}.getValue('Qty' + ':' + i);
var Desc = {dialog.object}.getValue('Desc' + ':' + i);
var Price = {dialog.object}.getValue('Price' + ':' + i);
text += "{qty: '' " + " , " + "desc: '" + "<strong> Total</strong>" + "' , " + "price: " + total + " , res: 'style= " + "\" text-align:right\"'" + "}]" ;
var before = "[{meal: '" + name + "', location: '" + location + "', table: "
text = before.concat(text);
text += "}];";
// the following three lines of code are for testing to look at the result.
document.getElementById("demo").innerHTML = text;
var text = document.getElementById("demo").innerHTML ;
document.getElementById("copy").innerHTML = text;
// I have cut and pasted from the div and manually set the obj to the output of text if I don't do this I cannot get it to work.
obj = [{meal: 'Lunch', location: 'Central', table: [{qty: 1 , desc: 'BLT' , price: 50 , res: '' },
{qty: 2 , desc: 'Classic Club' , price: 100 , res: '' },
{qty: 4 , desc: 'Santa Fe' , price: 200 , res: '' },
{qty: 3 , desc: 'Breakfast Special' , price: 150 , res: '' },
{qty: '' , desc: ' Total' , price: 500 , res: 'style= " text-align:right"'}]}];
return obj
}
Comment