Skip to content

Instantly share code, notes, and snippets.

@sohan
Created January 15, 2014 21:38
Show Gist options
  • Save sohan/8445209 to your computer and use it in GitHub Desktop.
Save sohan/8445209 to your computer and use it in GitHub Desktop.
Correct way of adding child views to a specific dom element in the parent's collection view in Chaplin.js. Uses the option listSelector instead of container. Reference: http://sohanjain.com/2014/01/chaplin-jss-container-containermethod-and-listselector-options/
define([
'views/base/view',
'jquery',
'text!templates/player-song.hbs',
], function(View, $, template) {
'use strict';
var PlayerSongView = View.extend({
autoRender: true,
autoAttach: true,
template: template,
className: 'song-container',
...
});
return PlayerSongView;
});
define([
'views/base/collection-view',
'jquery',
'text!templates/player-songs.hbs',
], function(CollectionView, $, template) {
'use strict';
var PlayerSongsView = CollectionView.extend({
template: template,
className: 'song-container',
listSelector: '.player-songs'
...
});
return PlayerSongsView;
});
<h1>Song Player</h1>
<div class="player-songs">
</div>
<div class="controls">
<button class="btn skip-song">Skip Song</button>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment