Being new to Backbone.js, just wanted to clarify the correct way to go about this simple task.
Developing a web app, almost always, you\'ll have user accounts, where use
There is not any reason to feel forced to declare a Collection
for every Model
your App has. It is very common to have Models without Collection associated.
// code simplified and not tested
App.CurrentUser = Backbone.Model.extend({
url: "http://myapp.com/session.json"
});
App.CurrentUserView = Backbone.View.extend({
el: "#user-info",
render: function(){
this.$el.html( "<h1>" + this.model.get( "name" ) + "</h1>" );
}
});
var currentUser = new App.CurrentUser();
currentUser.fetch();
var currentUserView = new App.CurrentUserView()({ model: currentUser });
currentUserView.render();
If you want a model / view with no collection, don't write a collection or collection view.
Add the view the same way you normally see the collection based view added.