Javascript Can';我搞不懂backbone.js
很抱歉,如果这是一个超级noob问题,但我正在拼命地学习Backbone.js以获得一份工作,我花了整整一周的时间在codeschool.com上阅读和观看视频,我仍然无法理解这一点 我试图将json文件呈现为模板中的表,但我无法找出我做错了什么,每次我尝试做的事情都会越来越糟 这是我的JS:Javascript Can';我搞不懂backbone.js,javascript,json,backbone.js,Javascript,Json,Backbone.js,很抱歉,如果这是一个超级noob问题,但我正在拼命地学习Backbone.js以获得一份工作,我花了整整一周的时间在codeschool.com上阅读和观看视频,我仍然无法理解这一点 我试图将json文件呈现为模板中的表,但我无法找出我做错了什么,每次我尝试做的事情都会越来越糟 这是我的JS: Game = Backbone.Model.extend({}); Games = Backbone.Collection.extend({ mo
Game = Backbone.Model.extend({});
Games = Backbone.Collection.extend({
model: Game
})
window.AllGames = new Games();
AllGames.fetch({
url: 'games_in_progress.json'
, success: function() {
//console.log(AllGames.toJSON());
}
});
GameList = Backbone.View.extend({
el: 'body',
listTemplate: _.template($('#game_list').html(), {}),
initialize: function(){
//this.render();
this.collection = new AllGames();
this.collection.bind("reset", this.render, this);
this.collection.fetch();
},
render: function(){
//var listTemplate = _.template($('#game_list').html(), {});
//this.$el.html(listTemplate);
console.log(this.collection.toJSON());
$(this.el).html(this.listTemplate(this.collection.toJSON()));
}
});
var gameList = new GameList({
el:$(".content")
});
以下是我尝试导入的json文件:
{
"title": "Tic Tac Toe Games in Progress",
"games": [
{"id": 1, "player1": "Eric Morgan", "player2": "Charles May", "player1_wins": 0, "player2_wins": 2},
{"id": 2, "player1": "Valerie Bowman", "player2": "Felicia Cole", "player1_wins": 0, "player2_wins": 0},
{"id": 3, "player1": "Guy Benson", "player2": "Norman Day", "player1_wins": 3, "player2_wins": 3},
{"id": 4, "player1": "Emanuel Weaver", "player2": "Sammy Nelson", "player1_wins": 10, "player2_wins": 4},
{"id": 5, "player1": "Oliver Mcbride", "player2": "Jill Hansen", "player1_wins": 102, "player2_wins": 30},
{"id": 6, "player1": "Alison Bell", "player2": "Owen Dixon", "player1_wins": 10, "player2_wins": 200},
{"id": 7, "player1": "Lawrence Adams", "player2": "Ebony Schmidt", "player1_wins": 1, "player2_wins": 0},
{"id": 8, "player1": "Tony Robbins", "player2": "Shelley Mills", "player1_wins": 5, "player2_wins": 21},
{"id": 9, "player1": "Dustin Watts", "player2": "Glen Clayton", "player1_wins": 12, "player2_wins": 19},
{"id": 10, "player1": "Douglas Bates", "player2": "Eduardo Martin", "player1_wins": 1, "player2_wins": 3},
{"id": 11, "player1": "Lola Swanson", "player2": "Nichole Carlson", "player1_wins": 101, "player2_wins": 0},
{"id": 12, "player1": "Fernando Mitchell", "player2": "Bessie Sharp", "player1_wins": 9, "player2_wins": 0},
{"id": 13, "player1": "Randal Austin", "player2": "Rodolfo Mccormick", "player1_wins": 7, "player2_wins": 90},
{"id": 14, "player1": "Louise Chandler", "player2": "Laura Beck", "player1_wins": 93, "player2_wins": 112},
{"id": 15, "player1": "Ernesto Brock", "player2": "Lois Singleton", "player1_wins": 109, "player2_wins": 87},
{"id": 16, "player1": "Lora Osborne", "player2": "Katie Johnston", "player1_wins": 201, "player2_wins": 7},
{"id": 17, "player1": "Priscilla Horton", "player2": "Julius Hale", "player1_wins": 10, "player2_wins": 53},
{"id": 18, "player1": "Andrew Fernandez", "player2": "Henrietta Morris", "player1_wins": 30, "player2_wins": 99},
{"id": 19, "player1": "Joe Shelton", "player2": "Martin Ramsey", "player1_wins": 34, "player2_wins": 20},
{"id": 20, "player1": "Mary Little", "player2": "Pam Goodwin", "player1_wins": 29, "player2_wins": 43},
{"id": 21, "player1": "Lynda Nguyen", "player2": "Jermaine Hughes", "player1_wins": 61, "player2_wins": 71},
{"id": 22, "player1": "Clifford Young", "player2": "Tonya Baldwin", "player1_wins": 0, "player2_wins": 0},
{"id": 23, "player1": "Adrienne Kennedy", "player2": "Jordan Howard", "player1_wins": 10, "player2_wins": 1},
{"id": 24, "player1": "Lena Newton", "player2": "Kristi Guerrero", "player1_wins": 30, "player2_wins": 1},
{"id": 25, "player1": "Alicia Casey", "player2": "Jody Lopez", "player1_wins": 0, "player2_wins": 0}
]
}
我知道这很糟糕,但我真的很喜欢脊梁骨,我真的很想学它。如果有人能帮忙,我将不胜感激
另外,如果有什么推荐书可以读,我也会很感激的。我目前正在阅读Thomas Davis()的“主干教程”,但如果有比此或codeschool.com更好的资源,我将不胜感激。对不起,我的浏览器关闭了一半的窗口: 请注意,在定义模板函数时,您已经通过提供空对象对其进行编译, 因此,您需要跳过定义中的空对象指定 正确的方法是这样的:
listTemplate:35;.template($(“#游戏列表”).html(),
谢谢。你有什么资源可以推荐我阅读,因为我完全迷路了。你是怎么学的?