How to put a reactive Template inside of a Surface

2019-08-03 14:33发布

I've read several posts on this but nothing that would really answer my question in an up-to-date way (i.e. UI.insert is depreciated).

So what's the best way of inserting/rendering a Template into a Surface reactively, meaning, not only one data object (renderWithData), but whatever is defined in the Template.helpers should also be updated reactively. Code tried so far:

var div = document.createElement('div');

//UI.insert(UI.render(function() { return Template.hello; }), div);
surface = new famous.core.Surface({
    //content: Blaze.toHTML(function() { return Template.hello; }),
    //content: div,
    content: '<div class="hell"></div>',
    size: [window.innerWidth, window.innerHeight],
    properties: {...}
  });
  Blaze.render(function() { return Template.hello}, $('.hell')[0]);

These are 3 different approaches I've tried. First UI.insert inserts it, but handlebars-style Helpers are not recognized. Second, toHTML, no reactivity, even when I put everything into a Tracker.autorun(). Third, Blaze.render(...), doesn't work at all.

Is there an easy solution to this?

1条回答
Root(大扎)
2楼-- · 2019-08-03 15:19

one possible answer is to use Famodev

var ReactiveTemplate = famodev.ReactiveTemplate;

var reactive = new ReactiveTemplate({
  template: Template.mytemplate,
  data: Collection.find().fetch(),
  properties: {
  }
});

Maybe it will be useful in some way http://github.com/dcsan/moflow

查看更多
登录 后发表回答