大佬教程收集整理的这篇文章主要介绍了javascript – Meteor 0.8 Blaze如何更新Jquery插件的渲染更改,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的例子中,我使用Footable Jquery插件来格式化表格.初始加载工作正常,但是如果我在Collection find中更改过滤器变量,则DOM会更新并且不会再次调用渲染,因为Blaze只调用一次渲染.我不想把它放到另一个模板中,因为这只意味着对渲染的多次调用,因此当它只需要一个整个表时,就会多次调用Footable.
任何帮助表示赞赏.
<template name="customerData"> <table class="table"> {{#each da@R_259_2301@ws}} <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; }
履行
UI.registerHelper('footableBody',function () { var dependency = new Deps.Dependency(),datasource = this,handle,footable; return UI.Component.extend({ render: function () { var self = this; return UI.Each(function () { return datasource; },UI.block(function () { dependency.changed(); return self.__content; })); },rendered: function () { var $node = $(self.firstNodE).closest('table'); handle = Deps.autorun(function () { if (!footablE) { $node.footable(); footable = $node.data('footable'); } else { footable.redraw(); } dependency.depend(); }); },destroyed: function () { handle && handle.stop(); },}); });
现在,在您的模板中,您可以执行以下操作:
<table class="table"> <thead> ... </thead> <tbody> {{#footableBody da@R_259_2301@ws}} <tr> <td>{{first_name}}</td> <td>{{last_name}}</td> <td>{{email}}</td> <td>{{phonE}}</td> </tr> {{/footableBody}} </tbody> </table>
当然,您应该根据自己的需要自定义帮助程序的行为.
思考
还有另一种 – 更通用的 – 解决方案遵循标记帮助程序如何实现here的模式.但是,我不鼓励将此策略应用于您的特定用例.
以上是大佬教程为你收集整理的javascript – Meteor 0.8 Blaze如何更新Jquery插件的渲染更改全部内容,希望文章能够帮你解决javascript – Meteor 0.8 Blaze如何更新Jquery插件的渲染更改所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。