[英]backbone Scroll Events not firing
define([
'jquery',
'underscore',
'backbone',
'collections/jobs',
'text!templates/jobs/list.html'
], function($, _, Backbone, JobCollection, JobListTemplate){
var JobWidget = Backbone.View.extend({
el: '#bbJobList',
initialize: function () {
// isLoading is a useful flag to make sure we don't send off more than
// one request at a time
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;
// fetch is Backbone.js native function for calling and parsing the collection url
this.jobCollection.fetch({
success: function (jobs) {
// Once the results are returned lets populate our template
$(that.el).append(_.template(JobListTemplate, {jobs: jobs.models, _:_}));
// Now we have finished loading set isLoading back to false
that.isLoading = false;
}
});
},
// This will simply listen for scroll events on the current el
events: {
'scroll': 'checkScroll'
},
checkScroll: function () {
console.log("Scrolling");
var triggerPoint = 50; // 100px from the bottom
if( !this.isLoading && this.el.scrollTop + this.el.clientHeight + triggerPoint > this.el.scrollHeight ) {
this.jobCollection.page += 1; // Load next page
this.loadResults();
}
}
});
return JobWidget;
});
我似乎无法从触发事件。 console.log甚至不会触发。 我也在尝试滚动Windows,el实际上是一个div。 有什么建议吗?
#bbJobList
元素应具有滚动条- overflow: auto|scroll
CSS规则。 否则滚动事件将不会触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.