define([
'jquery',
'underscore',
'backbone',
'collections/jobs',
'text!templates/jobs/list.html'
], function($, _, Backbone, JobCollection, JobListTemplate){
var JobWidget = Backbone.View.extend({
el: '#bbJobList',
initialize: function () {
_.bindAll(this, 'detect_scroll');
$(window).scroll(this.detect_scroll);
this.isLoading = false;
this.jobCollection = new JobCollection();
},
render: function () {
this.loadResults();
},
loadResults: function () {
var that = this;
// we are starting a new load of results so set isLoading to true
this.isLoading = true;
this.jobCollection.fetch({
success: function (jobs) {
$(that.el).append(_.template(JobListTemplate, {jobs: jobs.models, _:_}));
// Now we have finished loading set isLoading back to false
that.isLoading = false;
}
});
},
close: function(){
this.remove();
this.unbind();
}
});
return JobWidget;
});
关闭后如何删除RELOAD渲染? 我打算重新渲染,更新数据在我将从控制器中获取的模型中(如果可能的话)
我试过
this.render()
答案 0 :(得分:1)
如果您打算重新渲染视图,则不应将el指定给原型,例如el: '#bbJobList'
。
在实例化视图时,将视图附加到元素,如
var view = new JobWidget();
view.render();
view.$el.appendTo('#bbJobList');
关闭从DOM中删除视图的视图后,重新渲染视图,再次如上所述再次实例化。