【发布时间】:2013-12-24 00:27:57
【问题描述】:
我正在使用meteorjs 开发一个应用程序。我对流星完全陌生。在我的应用程序中,我使用带有流星的 dataTables 进行缩短、分页和搜索。
这是我的模板代码
<template name="questions">
<div class="col-md-3">
{{#constant}}
<table class="table table-striped table-bordered table-condensed table-hover listing"
id="content_listing-table">
<thead>
<tr>
<th>Questions</th>
</tr>
</thead>
<tbody>
{{#each questions}}
<tr>
<td>
<a href="#" data-id={{_id}} class="edit"> {{questionSubString question_text}}</a>
</td>
</tr>
{{/each}}
</tbody>
</table>
{{/constant}}
</div>
</template>
我的流星代码是
Template.questions.rendered = function () {
$("#content_listing-table").dataTable();
}
Template.questions.questions = function () {
return Meteor.questions.find({topic_id: Session.get("currentTopicId")})
}
我的问题是当我向数据库中添加一个问题时,它似乎没有出现在模板上。并产生异常。我知道这是因为 datatables 。文档更新时数据表不会更新。我尝试了许多来自stackoverflow的示例,但无法摆脱这个问题。我尝试通过动态附加行但它总是给我一个警告。它似乎并没有采取正确的方式。我可以动态地从元素中删除数据表吗?帮助将不胜感激 编辑:
$('#content_listing-table').dataTable().fnClearTable();
$('#content_listing-table').dataTable().fnAddData(Meteor.questions.find().fetch());
我正在尝试先清空表,然后再向其中添加数据。但这里是清空表格,不再添加数据。
【问题讨论】:
标签: meteor datatables jquery-datatables meteorite