Im quite new to backbone and trying to add an "load more"-button toe the project. I want the button to load lets say six new items from my collection every time it gets clicked. How would i implement that?
Right now i have the whole collection loaded when the view initziales. But i guess it would be better to just load six items? (the ones that will be visible) and then i want to append six new ones on every click on "load more".
Anyone the can show me/help me on this one?
Collection
define([
'Underscore',
'Backbone',
'app',
'VideoModel',
], function (_, Backbone, app, VideoModel) {
var VideoCollection = Backbone.Collection.extend({
model: VideoModel,
url: url,
parse: function (response) {
return response;
},
initialize: function() {
}
});
return VideoCollection;
});
Model
define([
'Underscore',
'Backbone',
'app',
], function (_, Backbone, app) {
var VideoModel = Backbone.Model.extend({
defaults: function() {
return {
data: {
id: "",
created: "",
timestamp: ""
}
};
},
clear: function() {
this.destroy();
}
});
return VideoModel;
});
View
define([
'Underscore',
'Backbone',
'app',
'VideoCollection'
], function (_, Backbone, app, VideoCollection) {
var StartView = Backbone.View.extend({
tagName: "section",
id: "start",
className: "content",
events: {
},
initialize: function(){
$(".container").html(this.el);
this.template = _.template($("#start_template").html(), {} );
this.collection = new VideoCollection();
this.render();
},
render: function(){
this.$el.html(this.template);
this.collection.fetch({
success: function (obj) {
var json = obj.toJSON()
for(var i=0; i<json.length; i++) {
}
}
});
},
kill: function() {
this.remove();
}
});
return StartView;
});