Search code examples
javascriptjquery-templatesknockout.js

Can knockout.js use templates to generate templates?


I'm trying to use knockout to templates to generate templates.

Along the lines of

Html:

<script id="searchField-template" type="text/html">
    <li data-bind="text: name"></li>
</script>

<script id="template-template"  type="text/html">
    <ul data-bind="template: { name: 'searchField-template', foreach: ${name} }" ></ul>
</script>    

JS:

var viewModel = {
    Title: [{
        name: "Title1"},
    {
        name: "Title2"},
    {
        name: "Title3"}],
    Manager: [{
        name: "Manager1"},
    {
        name: "Manager2"},
    {
        name: "Manager3"}],

    Defn: [{
        name: "Title"},
    {
        name: "Manager"}]

};

ko.applyBindings(viewModel);

runnable sample here: http://jsfiddle.net/scottwww/yQZUE/2/

It seems that the problem is with how curly braces are interpreted.

Any suggestions?


Solution

  • Here you go >

    http://jsfiddle.net/vwP3w/2/