[英]render kendo template inside an html table
Is it possible in any way to render the table rows of a table with a kendo template? 是否可以通过剑道模板以任何方式渲染表格的表格行?
Here's how it should look but it won't render the rows inside the table since a <table>
doesn't allow a <span>
or <script>
tag inside it 它的外观如下, 但是由于
<table>
不允许在其中包含<span>
或<script>
标记,因此它不会呈现表中的行
<table class="table-striped">
<span data-template="myTable" data-bind="source: numbers"></span>
<script id="myTable" type="text/x-kendo-template">
<tr>
<td>
<span data-bind="text:number"></span>
</td>
</tr>
</script>
</table>
<script>
var numbers = [{number:1},{number:2},{number:3}]
</script>
You could do it like this: 您可以这样做:
<table id="output" class="table table-striped"></table>
var tablerows = '';
var template = kendo.template("<tr><td><span>#: number #</span></td></tr>");
var numbers = [{number:1},{number:2},{number:3}];
for (var i=0; i<numbers.length; i++){
tablerows += template(numbers[i]);
}
$("#output").empty().append(tablerows);
You could also put the loop inside the template... 您也可以将循环放入模板中...
I was able to solve it by putting the <script>
tag for the template outside the table and binding from the <table>
by adding a <tbody>
tag inside the table like this: 我可以通过将模板的
<script>
标记放在表外并通过在<table>
添加<tbody>
标记与<table>
绑定来解决此问题,如下所示:
<table class="table-striped">
<tbody data-template="myTable" data-bind="source: numbers"></tbody>
</table>
<script id="myTable" type="text/x-kendo-template">
<tr>
<td>
<span data-bind="text:number"></span>
</td>
</tr>
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.