I am working on a backbone app, and was provided some sample code, the provider made the data into a for loop which generates a number, I don't want that. I need to enter in player names like Kobe, Lebron etc not player_1, player_2.
//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 not sure how I can turn this into a static piece so I can enter player names manually (name: mike, name: john) not that format of course but I dont want (name: player_1, name: player_2).
I console.logged teams.toJSON() I get the objects in the console, but I cant figure out how to get the raw JSON data so I can see how to structure a hardcoded JSON array.
names=['mike','john']; for (var i=0; i<names.length; i++) .... Same as any other language that has these basic constructs.