Durandal Notes
April 17, 2021
View Composition
- You define a template to include with Knockout's
data-bindattribute and specify a value forcompose. e.g.data-bind=compose: 'file/path' composeis a custom binding for Knockout- You can bind to a partial view, which will just be a plain HTML file e.g.
navbar.html. Partial views have no matching JavaScript file, and are stored in theviewsfolder. If you bind a partial without a viewmodel, it'll bind it to the parent element's viewmodel. - OR you can bind to a ViewModel, which will get the viewmodel, get it's matching view, bind them together, and then insert it into the DOM.
code
<section data-bind="compose: 'navbar.html'"></section>
<!-- just HTML, no JS involved -->
<section data-bind="compose: 'viewmodels/navbar'"></section>
<!-- get the viewmodel and the matching view, bind them together and insert into DOM -->