我有以下模板:
<template name="modalTest">
{{session "modalTestNumber"}} <button id="modalTestIncrement">Increment</button>
</template>
该session
助手只是Session
对象的中间人。我已将其modalTestNumber
初始化为0
.
我希望这个模板以其所有的反应性呈现到一个引导箱模式对话框中。我为此模板声明了以下事件处理程序:
Template.modalTest.events({
'click #modalTestIncrement': function(e, t) {
console.log('click');
Session.set('modalTestNumber', Session.get('modalTestNumber') + 1);
}
});
以下是我尝试过的所有事情,以及它们的结果:
bootbox.dialog({
message: Template.modalTest()
});
这会呈现模板,它看起来或多或少像0 Increment (in a button)
. 但是,当我Session
从控制台更改变量时,它不会更改,并且当我单击按钮时不会调用事件处理程序(console.log
甚至不会发生)。
message: Meteor.render(Template.modalTest())
message: Meteor.render(function() { return Template.modalTest(); })
Template
这些都与调用本身完全相同。
message: new Handlebars.SafeString(Template.modalTest())
这只是将模态体呈现为空。模态仍然会弹出。
message: Meteor.render(new Handlebars.SafeString(Template.modalTest()))
Template
和纯Meteor.render
调用完全一样;模板在那里,但它没有反应性或事件响应。
是不是我正在使用这种较少的引导程序包而不是标准包?
我怎样才能让它以适当的反应流星风格呈现?
侵入 Bootbox?
我只是尝试侵入bootbox.js
文件本身,看看我是否可以接管。我改变了一些东西,以便在bootbox.dialog({})
层我只需传递我想要渲染的模板的名称:
// in bootbox.js::exports.dialog
console.log(options.message); // I'm passing the template name now, so this yields 'modalTest'
body.find(".bootbox-body").html(Meteor.render(Template[options.message]));
body.find(".bootbox-body").html(Meteor.render(function() { return Template[options.message](); }));
这两个不同的版本(不要担心它们是两种不同的尝试,而不是同时)它们都以非反应性方式呈现模板,就像它们之前所做的那样。
入侵引导箱会有什么不同吗?
提前致谢!