我正在尝试在我的应用程序中实现无限滚动。所以我想在用户滚动时进行多个AJAX调用。所以我想从服务器上滚动获取一组新的记录。我有一个动作“ infiniteScrolled”,在滚动时会被我的自定义组件调用。
我的问题是,当我尝试再次调用this.get('handleGridPromise')时,它不会再次被触发(可能是因为Promise由第一个调用解决了) 我该如何解决呢?
handleGridPromise: function() {
var self = this;
var request = self.get('serverParams');
return new Ember.RSVP.Promise(function(resolve, reject){
var promise = self.updateRequest(request);
promise.then(function(updateRequest){
var deferred = self.doXhrPost(updateRequest, self.get('gridURL'), true, false);
deferred.then(function(response){
self.gridDataLoaded(response);
resolve(self.get('model.gridData'));
});
});
});
}.property('attr1', 'attr2'),
infiniteScrolled(record, index) {
Ember.set(this.get('serverParams'), 'recordstartindex', index);
Ember.set(this.get('serverParams'), 'recordendindex', index+50);
this.get('handleGridPromise').then((records) => {
const until = Math.min((index + 50), (this.get('model.gridData.length') - 1));
Ember.run.later(() => {
for (index; index < until; index++) {
if (records[index].id === undefined) {
records.replace(index, 1, this.get(`model.gridData.${index}`));
}
}
}, 500);
});
}