Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 1.13 KB

views.md

File metadata and controls

47 lines (36 loc) · 1.13 KB

Views

The examples in the the Views example folder illustrates how views can be used in a nested fashion to achieve complex behaviors. Take a look at them for examples and working code.

View nest naturaly; using a view in side a view is as simple as:

<div>
    <span>This is in the template for a view!</span>
    <div data-view="MyNestedView"></div>
</div>

Where the outer div in the above example is the template for the parent view.

To assign view models dynamically to a nested view use the 'o-view-model' binding:

<div>
    <span>This is in the template for a view!</span>
    <div 
        data-view="MyNestedView"
        data-bind="o-view-model: aViewModelMadeAvailableViaTheParentViewModel">
    </div>
</div>

Where the outer div in the above example is the template for the parent view.

Loops work as well:

<div>
    <span>This is in the template for a view!</span>
    
    <!-- ko foreach: viewModelItems -->
	<div 
        data-view="MyNestedView"
        data-bind="o-view-model: $data">
    </div>
	<!-- /ko -->
</div>

Where to go next?

Controls