Meteor 0.8 Blaze how to update rendered changes for Jquery plugins

前端 未结 1 462
别跟我提以往
别跟我提以往 2020-12-10 09:16

My question is how to get 1 event or rendered callback when a group of elements are updated in the DOM? If I follow the link in the Blaze wiki https://github.com/avital/mete

1条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 09:42

    The best solution would be to write a custom block helper. Lemme do it for you :)

    Implementation

    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();
        },
      });
    });
    

    Usage

    Now, in your templates you can do something like:

    
        ...
      
      {{#footableBody dataRows}}
        
      {{/footableBody}}
      
    {{first_name}} {{last_name}} {{email}} {{phone}}

    Of course you should customize the behavior of the helper to your own needs.

    Reflections

    There is also another - more generic - solution that follows the pattern of how markdown helper is implemented here. However, I would not encourage to apply this strategy to your specific usecase.

    0 讨论(0)
提交回复
热议问题