Questions tagged [knockout-templating]

Knockout templates are a simple and convenient way to build reusable view pieces, at the same time providing the option of repeating or nested blocks because they can recursively call themselves.

Knockout templates are a simple and convenient way to build reusable view pieces, at the same time providing the option of repeating or nested blocks because they can recursively call themselves.

A template in Knockout is defined using a <script> tag of type="text/html", e.g.:

<script type="text/html" id="person-template">
    <p>
        <span data-bind="text: surname"></span>
        (<span data-bind="text: firstname"></span>)
    </p>
</script>

Optionally, they can be recursive:

<script type="text/html" id="person-template">
    <p>
        <span data-bind="text: surname"></span>
        (<span data-bind="text: firstname"></span>)
    </p>
    <h4>Father:</h4>
    <div data-bind="template: { name: 'person-template', data: father }"></div>
</script>

References

62 questions
72
votes
1 answer

Knockout template using data-bind to image src property not working

I cannot see what is wrong here but the image does not display using the following Knockout template: I've tried this solution but didn't get it working.
KebdnK
  • 555
  • 1
  • 6
  • 23
8
votes
4 answers

Can I pass a variable in a template binding?

I know this isn't a good method to use long term, but for troubleshooting, is there any way I can pass a simple string while binding a template and then access it as a variable within the template? For instance, if this was my binding: CoinWidgetCom.go({ …
3
votes
1 answer

Rendering a knockout template with jQuery after page has loaded

I am building a knockout\jQuery plugin that creates it's own UI when invoked, like so: // renders ui $("#filter").myPlugin(); Usual jQuery stuff. However, as part of the behavior I wish to make use…
beyond-code
  • 1,423
  • 1
  • 12
  • 20
2
votes
1 answer

Javascript frameworks or knockoutjs library with nested Templating

Can I do nested templated with more than one hierarchy in for example kockoutjs library? http://knockoutjs.com/ or any other Javascript framework? I have this View: DataGrid: Cell1, Cell2, Cell3, Within Cell4 is a ListBox. Whatever it looks like in…
msfanboy
  • 5,273
  • 13
  • 69
  • 120
2
votes
1 answer

Collapse called twice inside accordion template

All works except for collapsing the Bootstrap collapsible outside of this example on stackoverflow, I would appreciate some suggestions. When any opened item is clicked to collapse, its class changes in the following sequence: panel-collapse…
2
votes
0 answers

Memory leak when switching between views in knockout single page application

My app consists of a shell view which loads sub views within it using knockout's templating engine. All the views are built on knockout. When navigating between views, the value of an observable changes indicating that a new view needs to be bound…
1
2 3 4 5