我有一个奇怪的问题,我的骨干视图没有显示,我没有错误。我遵循了我之前的程序,这些程序完全适用于发球台,但注意到这个观点似乎有效。
我很困惑,为什么它不能正常工作,你们可以看到最新情况。
如果我浏览代码,模型正在被正确获取并且其中有数据。
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;
}
});
答案 0 :(得分:2)
Render是一个返回此函数的函数,因此您正确链接,只需用
替换render.elrender().el