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
2
votes
1 answer

Knockout template binding loseing state

I'm using a template binding to render a set of radio buttons. There is also a css binding on the element. When a radio button is clicked, the viewmodel & view are are updated, but the checked state of the radio button is lost. Is there a work…
Homer
  • 7,594
  • 14
  • 69
  • 109
2
votes
1 answer

knockout data binding with "with" or foreach?

I am very new to Knockout and trying to explore it. I know how to use foreach but confuse about "with". I just gone through the documentation of knockout (http://knockoutjs.com/documentation/with-binding.html) for With. still like: 1) when should i…
Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90
2
votes
1 answer

dynamic data binding in nested templates in knockout js

I am using MVC framework and knockout js combination. I am bit new to knockout js. I need to bind data dynamically through API calls in my nested knockout templates. I am not finding any way about how to do that. my nested templates are: enter code…
1
vote
0 answers

Knockout nested $componentTemplateNodes returning wrong context's nodes?

I'm currently developing a layout engine using knockout as a base, but I've run into a bit of a snag. (sorry for the long post) I'm using Knockout 3.5.1. I have the following index.html:
Griffork
  • 683
  • 1
  • 5
  • 21
1
vote
1 answer

Remove a div based on the value of $index in knockout template

The following is my html code:
+
Kriti Chawla
  • 81
  • 1
  • 14
1
vote
2 answers

$item is not defined

My application uses it and has a problem with the $item field under Knockout 3.4.0. I need to access parentList, which stores the original parent element of an item that was dragged to another list. The code below will not run with the latest…
1
vote
1 answer

Unexpected token with Knockout 3 and jQuery Templates

My application has one binding that uses jQuery Templates plugin to bind Knockout templates. Since upgrading to Knockout 3.x I started seeing an error: Uncaught SyntaxError: Unable to process binding "template: function (){return {…
1
vote
2 answers

Passing parameter from Knockout template to modal

In this code example I'm looking for a way to pass parameters from data in Knockout's template into Knockout's data-bind that should ultimately appear in modal window. The result should be a modal window that displays a participant's name based on…
1
vote
1 answer

KO Cannot find template with ID

I am trying to bind a template to my view. But I keep getting template with ID error. Template: View :
user2904389
  • 43
  • 1
  • 7
1
vote
1 answer

Combine knockout template foreach with data

I want to display several URLs in table and put a remove button next to each one. Since this is used on several places I decided to use knockout templating.