我的ListClass看起来像这样:
var ListView = Backbone.View.extend({
initialize: function() {
this.render();
},
events: {
'click ul#perpage span': 'setperpage'
},
setperpage: function(event) {
this.collection.perpageurl = '/perpage/' + $(event.target).text();
this.collection.fetch();
this.render();
},
render: function() {
template = _.template('\
<table>\
<% _(collection).each(function(model){%>\
<tr><td><%=model.id%></td><td><%=model.name%></td><td><%=model.email%></td></tr>\
<%}); %>\
</table>\
<ul id="perpage">\
<li><span>5</span></li>\
<li><span>10</span></li>\
</ul>\
');
var context = {collection: this.collection.toJSON()};
$(this.el).html(template(context));
$('#app').html(this.el);
return this;
}
});
出于某种原因,当我第一次访问加载此视图的页面时,会显示5个项目(应该会发生)。但是当我点击“setperpage”事件时点击 <span>10</span>
,即使网址已更新,然后 fetch()
被调用,列表永远不会更新。 (我已经看过萤火虫的请求了,所以我知道我在json中找回了10个项目)。他们为什么不重新渲染?我仍然只看到5个项目。