Meteor - 如何在 bootbox 中使用 Blaze.renderWithData 并使结果保持反应性?
Meteor - How to use Blaze.renderWithData in a bootbox and have the result remain reactive?
我正在使用以下内容:
let box = bootbox.dialog({title:'',message:''});
box.find('.bootbox-body').remove();
Blaze.renderWithData(template,doc,box.find(".modal-body")[0]);
它呈现正确,但不是反应性的。
我怀疑我在直接传递文档时遇到了问题,并且文档的 _id 可用。
我应该将什么传递给 renderWithData 以使结果具有反应性?
如果在引导框之前的代码中有 doc = MyCollection.findOne(...)
,那么 doc
将是反应式的。否则你可以传入 _id
并在你的模板助手中执行 .find()
(你传递给 Blaze.render()
.
我找到了我的解决方案。
而不是
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]);
这现在使对话框具有反应性。
我正在使用以下内容:
let box = bootbox.dialog({title:'',message:''});
box.find('.bootbox-body').remove();
Blaze.renderWithData(template,doc,box.find(".modal-body")[0]);
它呈现正确,但不是反应性的。
我怀疑我在直接传递文档时遇到了问题,并且文档的 _id 可用。
我应该将什么传递给 renderWithData 以使结果具有反应性?
如果在引导框之前的代码中有 doc = MyCollection.findOne(...)
,那么 doc
将是反应式的。否则你可以传入 _id
并在你的模板助手中执行 .find()
(你传递给 Blaze.render()
.
我找到了我的解决方案。
而不是
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]);
这现在使对话框具有反应性。