[英]how to create backbone view with more link button?
我想你可以做这样的事情?
ExpandableView = Backbone.View.extend({
itemTemplate: _.template('<button name="<%=name%>" id="<%=name%>" value="<%=name%>"><%=name%></button>'),
id: 'expand',
events: {
'click #more': 'more'
},
initialize: function(opt) {
// attach to the main body
$(opt['main']).append(this.el)
this.counter = 3;
this.render();
},
more: function() {
this.counter += 3;
this.render();
},
render: function() {
$(this.el).html('');
for (var i = 0; i < this.counter; i++) {
$(this.el).append(this.itemTemplate({name: i}));
}
$(this.el).append(this.itemTemplate({name: 'more'}));
return this;
}
});
var search_view = new ExpandableView({ main: $('body') });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.