Skip to content

Instantly share code, notes, and snippets.

@tdreyno
Created September 23, 2012 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdreyno/3773259 to your computer and use it in GitHub Desktop.
Save tdreyno/3773259 to your computer and use it in GitHub Desktop.
An Ember.js Collection view which has childViews depending on a property of the data row.
FS.MultiplexingCollectionView = Em.CollectionView.extend({
itemViewClass: Em.View,
typeProperty: "type",
viewMap: {},
createChildView: function(view, attrs) {
var map = this.get("viewMap");
var prop = this.get("typeProperty");
if (attrs.content[prop] && (klassName = map[attrs.content[prop]])) {
view = Ember.getPath(klassName);
}
return this._super(view, attrs)
}
});
FS.SlidesCollectionView = FS.MultiplexingCollectionView.extend({
typeProperty: "type",
viewMap: {
interstitial: "FS.InterstitialView",
grid: "FS.GridView",
leader_board: "FS.LeaderboardSlideView"
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment