1
我通過peepcode backbone.js基礎教程工作,並且據我所知,我的代碼與截屏相同,但是我的控制檯行爲非常不同。backbone.js fetch()返回對象而不是子
我的Chrome控制檯(用於screecast)會產生此結果。
albums = new Albums()
child
albums.fetch()
Object
albums.models()
TypeError: Property 'models' of object [object Object] is not a function
的截屏控制檯看起來像這樣
albums = new Albums()
inherits.child
albums.fetch()
inherits.child
albums.models()
[ inherits.child, inherits.child ]
我完全失去了在何處,這是分崩離析。它是我的代碼(見下文),我的瀏覽器還是其他東西?
(function($) {
window.Album = Backbone.Model.extend({
isFirstTrack: function(index) {
return index == 0;
},
isLastTrack: function(index) {
return index >= this.get('tracks').length - 1;
},
trackUrlAtIndex: function(index) {
if (this.get('tracks').length >= index) {
return this.get('tracks')[index].url;
}
return null;
}
});
window.Albums = Backbone.Collection.extend({
model: Album,
url: "/albums"
});
window.AlbumView = Backbone.View.extend({
tagName: 'li',
className: 'album',
initialize: function() {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
this.template = _.template($('#album-template').html());
},
render: function() {
var renderedContent = this.template(this.model.toJSON());
$(this.el).html(renderedContent);
return this;
}
});
})(jQuery)
歡迎來到快活的主幹世界:) – 2012-07-17 13:01:39