我的问题是如何在DOM中更新一组元素时获得1个事件或渲染回调?如果我按照Blaze wiki https://github.com/avital/meteor-ui-new-rendered-callback中的链接,这不是我想要的.如果我遵循第二个建议,我将获得尽可能多的渲染调用,因为我有元素.并且父元素只会在页面加载时获得1个渲染回调.
在我的例子中,我使用Footable Jquery插件来格式化表格.初始加载工作正常,但是如果我在Collection find中更改过滤器变量,则DOM会更新并且不会再次调用渲染,因为Blaze只调用渲染一次.我不想把它放到另一个模板中,因为这只意味着对渲染的多次调用,因此当它只需要一个整个表时,就会多次调用Footable.
任何帮助表示赞赏.
<template name="customerData">
<table class="table">
{{#each dataRows}}
<tr>
<td>{{first_name}}</td>
<td>{{last_name}}</td>
<td>{{email}}</td>
{{#each phones}}
<td>{{phone}}</td>
{{/each}}
</tr>
{{/each}}
</table>
</template>
Template.customerData.rendered = function(){
$(".table").footable();
}
Template.customerData.phones = function(){
var result = [];
_.each(this.phoneNumbers, function(element, index, list){
result.push({ phone: element});
});
return result;
}
Run Code Online (Sandbox Code Playgroud)