1

我正在尝试在 underscorejs 使用主干呈现的模板中使用数据表。我的模板代码是这样的:

<script type="text/template" id="ledgerListing">
<table>
<thead>
<tr><th>Name</th><th>Email</th><th>Phone</th><th>address</th></tr>
</thead>
<tbody>
<tr><td>mrinal</td><td>mrinal</td><td>mrinal</td><td>mrinal</td></tr>
</tbody></table>
</script>

在我的一个观点中,我做了一个这样的功能:

            ledgerTemplate: _.template($("#ledgerListing").html()),
            loadLedger: function(){

    this.container.html(this.ledgerTemplate());
    }

在页面顶部,我像这样初始化数据表:

$(document).ready(function() {
            $('table').dataTable();
        } );

表格被渲染,但未应用数据表插件。我猜脚本标签中的任何内容在页面加载期间都没有连接到 DOM。如果是这种情况,那么在下划线js呈现的模板上应用数据表的方法是什么。有什么建议么...

4

1 回答 1

1

好的,它对我有用。我真的是个傻子:)

只需要在模板填充后初始化数据表,如下所示:

this.container.html(this.ledgerTemplate());
    $('table').dataTable();
于 2013-01-19T10:24:36.067 回答