【问题标题】:Meteor - How to use Blaze.renderWithData in a bootbox and have the result remain reactive?Meteor - 如何在引导箱中使用 Blaze.renderWithData 并使结果保持反应性?
【发布时间】:2016-04-18 21:29:07
【问题描述】:

我正在使用以下内容:

let box = bootbox.dialog({title:'',message:''});
box.find('.bootbox-body').remove();
Blaze.renderWithData(template,doc,box.find(".modal-body")[0]);

它可以正确渲染,但不是反应式的。

我怀疑我在直接传递文档时遇到问题,并且文档的 _id 可用。

我应该将什么传递给 renderWithData 以使结果具有反应性?

【问题讨论】:

    标签: templates meteor meteor-blaze bootbox


    【解决方案1】:

    如果在引导箱之前的代码中有doc = MyCollection.findOne(...),那么doc 将是被动的。否则,您可以传入_id 并在模板助手中执行.find()(您要传入Blaze.render() 的那个。

    【讨论】:

    • 1) 实际上,doc 是使用 doc = MyCollection.findOne({_id}) 加载的,但是将结果传递给 Blaze.renderWithData,它不再是响应式的。
    • 2) 我不确定如何将 _id 传递给 Blaze.renderWithData。它需要数据,而不是 _id。
    • 取决于模板是如何设置的以及它的助手是什么。它需要一个数据上下文,它可以是从光标到对象数组到单个对象再到标量值的任何东西。
    【解决方案2】:

    我找到了解决办法。

    而不是

    let doc = MyCollection.findOne({_id});
    Blaze.renderWithData(template,doc,box.find(".modal-body")[0]);
    

    或者

    Blaze.renderWithData(template,MyCollection.findOne({_id}),box.find(".modal-body")[0]);
    

    我换了

    Blaze.renderWithData(template,function(){
      MyCollection.findOne({_id})
    },box.find(".modal-body")[0]);
    

    这现在使对话框反应。

    【讨论】:

      猜你喜欢
      • 2016-02-04
      • 2016-03-30
      • 1970-01-01
      • 2021-07-19
      • 1970-01-01
      • 1970-01-01
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多