Normally when I use jquery to build a simple app to show data, I would simply change some global variables depending on certain actions and then when I was ready to retrieve data from the server, I'd pass those vars along to the server.
What is a good way to do this in backbone.js? Does my view handle that? I have this view so far:
var ListView = Backbone.View.extend({
initialize: function() {
this.render();
},
render: function() {
template = _.template("\
<table>\
<% _(collection).each(function(model){%>\
<tr><td><%=model.name%></td><td><%=model.email%></td></tr>\
<%}); %>\
</table>\
");
var context = {collection: this.collection.toJSON()};
$(this.el).html(template(context));
$('#app').html(this.el);
}
});
Basically in my controller I create a users
collection and then I use users.fetch()
and then pass the users
collection to a new ListView
object. The initialize function automatically renders (is this bad practice?) I know there's events in backbone.js, and I'm guessing that's where this needs to end up. How do I handle sorting by certain fields or searching for certain text in certain fields or choosing how many results come back (i.e. 10 per page), etc.?