[英]Backbone.js fetch() returning object instead of child in server instance but in local instance retrieves child
[英]backbone.js fetch() returning object instead of child
我遍历了peepcode boundary.js基础教程,据我所知,我的代码与截屏视频相同,但是控制台的行为却大不相同。
我的Chrome控制台(在广播中使用)产生了此结果。
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)
您的代码很好,示例/截屏有错误,或者正在使用较旧的或更老的chrome实施,并且正在使用较旧的chrome,因此child VSInherits.child输出。
Backbone.Collection
模型方法-它是模型实例上的属性,应该由albums.models
而不是albums.models()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.