所以我正在学习backbonejs,使用nodecellar-rethinkdb例子作为练习
将 Backbone.js 和 Underscore.js 文件更新到最新版本后,我收到一条错误消息,提示“页面未定义”。相同的代码适用于 Backbone.js 0.9.2。所以我想有些东西被弃用了。
这是给我错误的分页文件的代码:
window.WineListView = Backbone.View.extend({
initialize: function () {
this.render();
},
render: function () {
var wines = this.model.models;
var len = wines.length;
var startPos = (this.options.page - 1) * 8;
var endPos = Math.min(startPos + 8, len);
$(this.el).html('<ul class="thumbnails"></ul>');
for (var i = startPos; i < endPos; i++) {
$('.thumbnails', this.el).append(new WineListItemView({model: wines[i]}).render().el);
}
$(this.el).append(new Paginator({model: this.model, page: this.options.page}).render().el);
return this;
}
});
window.WineListItemView = Backbone.View.extend({
tagName: "li",
initialize: function () {
this.model.bind("change", this.render, this);
this.model.bind("destroy", this.close, this);
},
render: function () {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});
你能告诉我为什么代码不能使用最新版本的原因,并修复它以使用最新的backbone.js
提前致谢。
尝试自己保留对选项的引用,我认为新版本的主干不会保留它。
Backbone.View.extend({
initialize: function (options) {
//add this
this.options = options; // or this.page = options.page and update render accordingly
this.render();
},
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句