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

Using nested knockout templates to display nested data

I am trying to make a table with collapsible rows using knockout. Each "parent" row exists at the top level of my data structure, and each "child" row is an element of a member array. The problem comes when I update the data from the server. The…
0
votes
1 answer

Nested templates

I have the following code: function Session(name, index) { this.Messages = []; this.Name = name; this.Index = index; } var vm = {}; vm.Sessions = ko.observableArray([new Session("Foo", 0), new Session("Bar",…
0
votes
1 answer

knockout template observable not working when passing value to inner template

I am rendering a template that accepts an observable array and inside, it uses an inner template to render the content of a property as input text. If I directly render input text in the "foreach" in the parent then any changes to the text are…
0
votes
0 answers

Knokcout JS: Uncaught ReferenceError: action is not defined

I am currently using knokcout js to render a view. HTML:
0
votes
1 answer

Uncaught ReferenceError: Unable to process binding "template: function (){return { foreach:third} }" Message: third is not defined in knockout js

I am still new to KnockoutJs, I am having an issue with data binding the table will have uncaught Reference error on binding.. I am calling data via ajax call and compared with another array and store the compared value in one variable. These…
0
votes
1 answer

Knockout property datepicker not working

I am trying to bind a datepicker to my template property in knockout as per this example: http://jsfiddle.net/H8xWY/130/ From fiddler it looks pretty straightforward but the issue is that when I focus on date textbox the datepicker doesn't come up…
nickornotto
  • 1,946
  • 4
  • 36
  • 68
0
votes
1 answer

creating knockout template for table row

I'm trying to create a knockout template that should generate a table row for each row in the knockout array. When I add the below code it tells me "element script cannot be nested inside element table" …
shw
  • 135
  • 3
  • 12
0
votes
2 answers

Knockout.js template binding - call a function of tinyMCE to load preview

I am using KO.JS and building a html template. I want to display TinyMCE Preview by calling its preview command in the html binding. In general, this is how we render the preview for tinymce on an external button click : var preview = function…
user2598808
  • 633
  • 5
  • 22
  • 40
0
votes
1 answer

How to create a tree structure in Knockout using a Knockout template?

I am working with Knockout support and now creating tree structured UI component. Here i will create the elements dynamically and there i want to bind the data to newly created elements. Please check with the below code
0
votes
0 answers

Knockout template engine. Transfer view model in the following template

I'm new to knockout template engine and I've run into an issue. I have a container that contains text input with clickable hints. My aim is to change input text with link caption after it is clicked by user. html code snippet:
0
votes
1 answer

Two-dimensional knockout sortable not updating UI

I'm creating a two-dimensional sortable container with first dimension (rows in table) and second dimension (cells in a row). The cells should be draggable within a row, to existing rows, to new rows created dynamically. Empty rows should be…
0
votes
2 answers

Knockout nested sortable sourceParent.splice is not a function

Here I'm working on code that uses Knockout sortable. It should display nested sortables 3+ levels in depth. The data are passed to the template, but some elements return to their original position after being dropped (e.g. A,B elements on uppermost…
0
votes
1 answer

Turn cell content to editable input box

When creating a fluid layout, where content can be dragged around and edited inside a table I ran into a problem. After clicking on any of the hyperlinks the cell content should be replaced by an editable input box. This gets done, but the…
Peter G.
  • 7,816
  • 20
  • 80
  • 154
0
votes
2 answers

Knockout: viewModel is not defined

When using this JSFiddle as a reference to build a grid with organizable contents I ran into a problem. An error message says Error: viewModel is not defined. It should normally work as in the example, since my viewModel is defined on the first line…
Peter G.
  • 7,816
  • 20
  • 80
  • 154
0
votes
1 answer

KnockoutJS: Make nested sortable automatically expand when adding a child

In the attached example I have a nested sortable that is capable of displaying tree structures. The goal is to make the structure expand when new child is added to make the change visible. A function automatically expands the structure when a new…
Peter G.
  • 7,816
  • 20
  • 80
  • 154
ID#