I am currently developing a backbone application and have been given some sample code by the provider. The code includes a for loop that generates player names as 'player_1', 'player_2', and so on. However, I would like to manually enter player names such as Kobe, Lebron, etc instead of the generated format.
//generate 20 players
for(var i=1; i <= 20; i++) {
players.add({
id: i,
name: 'player_' + i,
score: Math.floor((Math.random()*20)+20)
});
}
//generate 4 teams, and assign players to them at the same time...
for(var i=1; i <= 4; i++) {
teams.add({
id: i,
name: 'team_' + i,
players: new App.Collections.Players(players.filter(function(player) {
return (player.id <= i*5 && player.id > (i-1)*5);
}))
});
}
I am unsure how to convert this into a static structure where I can manually input player names like 'mike', 'john' instead of the default 'player_1', 'player_2' format.
Upon console logging teams.toJSON()
, I can see the objects in the console but I am struggling to extract the raw JSON data to understand how to create a hardcoded JSON array.