var masterArry=[];
var strikeArr=[];
var callArr=[];
var putArr=[];
//strikeArr populated
//callArr populated
//putArr populated
masterArry.push(strikeArr);
masterArry.push(callArr);
masterArry.push(putArr);
res.render('index', {items:masterArray});
In index html page, this is not working
<script>
alert(items[1]); //I expect this to print callArr
</script>
Nope. I don’t think you can do this with Node and HTML alone. It’s not like using PHP, where you can echo stuff to the page without any further setup necessary.
okay. fine. if its not doable by javascript , let me try with template then.
I’m already using handlebar template in index.hbs page
Here is a bad handlebar code . I am not sure how to fix this but this is what I need.
{{# each items }}
<div>
<script>
var strikeData="{{this[0]}}"
var callData="{{this[1]}}"
var putData="{{this[2]}}"
// I can now invoke highcharts charting libary and pass these JS data arrays to chart.
</script>
</div>
{{/each}}
this is current server code and this is the log in server console.
console.log("************FEST*******************");
console.log("openinterestdocs" + openinterestdocs);
console.log("openinterestdocs.length =" + openinterestdocs.length);
var masterArry = [];
var strikeArr = [];
var callArr = [];
var putArr = [];
for (i = 0; i < openinterestdocs.length; i++) {
var jsonData = openinterestdocs[i];
var rowList = jsonData.rows;
for (j = 0; j < rowList.length; j++) {
//console.log(rowList[j].c[0].v);
strikeArr.push(rowList[j].c[0].v);
//console.log(rowList[j].c[1].v);
callArr.push(rowList[j].c[1].v);
//console.log(rowList[j].c[2].v);
putArr.push(rowList[j].c[2].v);
}
masterArry[i].push(strikeArr);
masterArry[i].push(callArr);
masterArry[i].push(putArr);
console.log(masterArry); // Log not printed !!
}
res.render('index', {
items: bankniftydocs,
niftyitems: niftydocs,
oidata: masterArry
});
server log
This is the current handlebar code
<script>
const oidata=[{{oidata}}];
var arrayLength = oidata.length;
for (var i = 0; i < arrayLength; i++) {
alert(oidata[i][0]); // no alert
alert(oidata[i][1]); // no alert
alert(oidata[i][2]); // no alert
}
</script>
I think issue is with server code. Please see the previous server code, specifically this part
masterArry[i].push(strikeArr); // can I write this ?
masterArry[i].push(callArr);
masterArry[i].push(putArr);
console.log(masterArry); **// Log not printed !!**