jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – Meteor 0.8 Blaze如何更新Jquery插件的渲染更改大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的问题是如何在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 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;
}

解决方法

最好的解决方案是编写自定义块帮助程序. Lemme为你做:)

履行

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,请注明来意。