Skip to content

Template convention

AndersMalmgren edited this page Dec 19, 2012 · 12 revisions

Any type of object or array of items where the item satisfy the condition

typeof === "object" //Excluding strings, booleans, numbers, etc

Can be bound to a arbitrary element but the element in question must not contain children. By convention the library will look for a template with the same name as the ViewModel minus the postfix 'ViewModel'. A model named CustomerViewModel will be binded to a template named CustomerView.

<div data-name="subView"></div>

<script id="SubTestView" type="text/html">
   <span data-name="value"></span>
</script>

http://jsfiddle.net/xJL7u/

Note

Javascript is a dynamic language so to find the type name of a ViewModel the library has to iterate the entire window object to find your constructor and then match that to the member of the parent. To make this process faster and more secure always specify your object root (Namespace). This way the library only needs to iterate your appslications object tree.

ko.bindingConventions.init({ roots: [MyApp] });
Clone this wiki locally