javascript - 延迟加载集合时如何获取获取的模型?

标签 javascript backbone.js

我有一个很长的视频列表,我已将延迟加载添加到此列表中:

//file videos.js
loadMore: function(){
   this.fetch({
       add: true, //add to collection 
       data: {
           limit: this.limit, 
           offset: this.offset
       }
   });
   this.offset += this.limit;
}

此提取会触发 View 的 add 事件。

//file videosView.js
initialize : function() {
    collection.bind('add', this.addVideo, this);
},

addVideo: function() {
    //how can I get the added models?
},

在 View 中,如何获取添加的模型?

最佳答案

只需在您的添加回调函数中请求它:

addVideo: function(video) {
    // the model that was added is in the video variable
}

关于javascript - 延迟加载集合时如何获取获取的模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8561527/

相关文章:

javascript - 将 jquery-ui 事件绑定(bind)到主干事件

javascript - 使用 == 比较整数与字符串时 JavaScript 中的隐式数据类型转换

Backbone.js 和无脂框架 : moving data around

javascript - Marionette 模块未触发 'start' 事件

javascript - 当前用于将 html + svg + css 转换为 pdf 的库

url - 如何使用主干在集合和模型中创建动态 url

javascript - 在 backbone.js 中使用绑定(bind)传递上下文

javascript - 将参数传递给事件函数

javascript - JavaScript 函数中 ~ 的含义

javascript - 按键 [tab、shift、上/下/左/右箭头] 和 firefox