我有一个奇怪的问题,我的主干 View 没有显示,但我没有收到任何错误。我遵循了之前的程序,该程序完美地发挥了作用,但注释似乎适用于此 View 。
我很困惑为什么它不起作用,希望你们中的一个人能看到发生了什么。
如果我浏览代码,模型将被正确获取并且其中有数据。
main.js
this.absences = new AbsenceCollection({idC:id},{option: 0});
this.absences.fetch({success: function(){
$('#contents').html( new AbsenceListView ({model: app.absences}).render.el,id);
}});
AbsenceList.js
window.AbsenceListView = Backbone.View.extend({
tagName:'table',
initialize:function () {
this.model.bind("reset", this.render, this);
var self = this;
this.model.bind("add", function (absence) {
$(self.el).append(new AbsenceListItemView({model:absence}).render().el);
});
},
render:function (eventName) {
_.each(this.model.models, function (absence) {
$(this.el).append(new AbsenceListItemView({model:absence}).render().el);
}, this);
return this;
}
});
window.AbsenceListItemView = Backbone.View.extend({
tagName:"tr",
initialize:function () {
this.template = _.template(tpl.get('absence-table'));
this.model.bind("change", this.render, this);
this.model.bind("destroy", this.close, this);
},
render:function (eventName) {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});
缺勤模型
window.Absence = Backbone.Model.extend({
//SIMS/resource/class datatables http//localhost:8080
baseURL: "http://localhost:8080/SIMS/resource/absence",
url: function() {
return this.baseURL + '/' + idClass + '/' + option;
},
initialize: function(attributes, options){
option = options.option;
idClass = attributes.idC;
},
defaults: {
"week":"",
"StudentidStudent":"",
"classidClass":"",
"monday":"",
"tuesday":"",
"wednesday":"",
"thursday":"",
"friday":""
}
});
window.AbsenceCollection = Backbone.Collection.extend({
model: Absence,
baseURL: "http://localhost:8080/SIMS/resource/absence",
url: function() {
return this.baseURL + '/' + idClass + '/' + option;
},
initialize: function(attributes, options){
option = options.option;
idClass = attributes.idC;
}
});
最佳答案
Render 是一个返回此值的函数,因此您的链接正确,只需将 render.el 替换为
render().el
关于javascript - Backbone View 未显示且未显示任何错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22774149/