meteorjs中的数据表不更新 [英] datatables are not updating in meteorjs
问题描述
这是我的模板代码
< 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>问题< / 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)})
}
我的问题是我添加问题到数据库,它似乎没有模板。并产生异常。我知道这是因为数据。并且当更新文档时,datatable不会更新。我尝试了很多来自stackoverflow的例子,但无法摆脱这个问题。我尝试通过动态追加行,但总是给我一个警告。它似乎没有正确的做法。我可以动态地从元素中删除数据表吗?帮助将被赞赏
编辑:
$('#content_listing-table')。dataTable()。fnClearTable );
$('#content_listing-table')。dataTable()。fnAddData(Meteor.questions.find()。fetch());
我试图这样做首先清空表,然后再次添加数据。但是在这里,它没有再次添加数据,而是清空表。
您正在使用 {constant}}
区域。这将禁用该模板部分的反应。
尝试使用 meteor --release template-engine- preview-5.5
。这将使用新的,正在进行的模板引擎Meteor UI来运行流星。在Meteor UI中没有常量
s或保留
- 足够聪明,使DOM更改为细粒度级别,所以它应该像jQuery插件一样工作。
I am working on an application using meteorjs. I am totally new to meteor. In my application I am using dataTables with meteor for shorting , pagination and searching.
This is my template code
<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>
and my meteor code is
Template.questions.rendered = function () {
$("#content_listing-table").dataTable();
}
Template.questions.questions = function () {
return Meteor.questions.find({topic_id: Session.get("currentTopicId")})
}
my problem is when i add a question to the database it doesn't seem on template. and generate an exception. I know this is because of datatables . and datatable is not update when document updated. i tried many examples from stackoverflow but couldn't get rid of this problem .I tried by appending row dynamically but it always give me a warning . and it doen't seems to do a right way. can i remove the datatables from the element dynamically? help will be appreciated EDIT:
$('#content_listing-table').dataTable().fnClearTable();
$('#content_listing-table').dataTable().fnAddData(Meteor.questions.find().fetch());
I am trying to do this first empty the table and then again add the data to it. But here it is emptying the table for not adding the data again.
You are using a {{constant}}
region. This disables reactivity for that part of the template.
Try getting rid of your constant region and run meteor using meteor --release template-engine-preview-5.5
. This will run meteor using the new, in progress template engine Meteor UI. There are no constant
s or preserve
s in Meteor UI - it's smart enough to make DOM changes at a fine-grained level, so it should work out of the box with things like jQuery plugins.
这篇关于meteorjs中的数据表不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!