Day 54, Thorax 101

Only after using it for three weeks, I begun to understand the differences between Thorax and Backbone

– Thorax automatically fetch model/collection for a view when:

var view = new Thorax.View({
  model: myModel
});

var view = new Thorax.View({
  collection: myCollection
});

//SO
//Please don't try to fetch again

– “Note that while any view may bind a collection only a CollectionView will actually render a collection. A regular Thorax.View may declare a collection helper which in turn will generate and embed a CollectionView.” This means:

//in your admin.js file
var view = new Application.Views["web/admin"]({
  collection: admin
});
view.admin = admin; // this is absolutely necessary if view is a regular Thorax.View
Application.setView(view);    

//so that you can do this in your template, which is your admin.handlebars
{{#collection admin}}
  {{name}} //name is a property of the model inside the collection
{{/collection}}
Advertisements
Standard