So on my Jade template, I am passing it a variable through the route which contains an array of names.
Here is the JavaScript from that template:
script(type='text/javascript')
window.teams = !{JSON.stringify(teams)};
teams contains the array I spoke about. Here is the JavaScript:
$(function () {
// Array of team names
var teamNames = [];
for(var i = 0; i < teams.length; i++) {
teamNames.push(teams[i].name);
}
var bracketTeams = [];
var teamMatches = new Array();
for(var i=0;i<teamNames.length; i+=2)
{
teamMatches.push([teamNames[i],teamNames[i+1]]);
}
var bracketData = {
teams : teamMatches,
results : [[
[ [1, 0], [1, 0] ],
[ [1, 0], [1, 0] ]
]]
}
$('#tournamentBrackets').bracket({
init: bracketData
});
});
Now for some reason, the functionality of the rest of the system completely breaks when I add in this JavaScript code. If I comment it out, then the rest of the system works fine, if I leave it in, buttons do nothing, links go nowhere, data isn't added (although the data is loaded, i.e a database of teams is listed). If I load the page, then uncomment the JS, the page works as it should though.
Any ideas what is breaking my system in this code? I just tried renaming window.teams to window.testName and it still broke. Really confused.
EDIT: HTML generated
In Node.js, the window object probably does not exist. Node.js has a different global object than browsers do. In Node.js, the global object is actually named global. Unless you have specifically set up an object named window, you're probably getting a ReferenceError when you try to assign values to window.teams