0

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"

<table>
<tr>
    <th>ID#</th>
    <th>Name</th>
</tr>
<tr data-bind="template: { name: 'EmployeeTemplate', foreach: EmployeesArray }"></tr>
<script type="text/html" id="EmployeeTemplate">
    <td>234567899874</td>
    <td>Mr. Test </td>
</script>

How can I resolve this using knockout templates? I'm basing it off this link.

shw
  • 135
  • 3
  • 12

1 Answers1

4
<script type="text/html" id="templateName">
    <td data-bind="text: Property"></td>
    <td data-bind="text: Property"></td>
</script>   

<tbody data-bind="foreach: data">
  <tr data-bind="template: { name: 'templateName', data: $data }"></tr>
</tbody>

This should work.

Nimesco
  • 688
  • 4
  • 13
  • in order to use the templates I need to put a script tag - I'm basing it off of this link: http://knockoutjs.com/documentation/template-binding.html – shw Jun 28 '17 at 13:22
  • and then I should move the script tags out of the table? – shw Jun 28 '17 at 13:36