我不想使用 jQuery,而是想通过“Meteor-way”将回调绑定(bind)到 Semantic-UI 模块,有点像 Bootstrap 3 允许的,例如:
Template.someTemplate.events({
'show.bs.dropdown .someDropdown': function () {
// official Bootstrap JS callback for the Dropdown module's show event
}
});
使用 Semantic-UI,似乎我只能在包含模板的 onRendered()
回调中使用 jQuery 绑定(bind)时定义回调函数,例如:
Template.someTemplate.onRendered( function () {
this.$('.someDropdown').dropdown({
'onShow': function () {
// official Semantic-UI JS callback for the Dropdown module's show event
}
});
});
这不是最佳选择,因为 (a) 在特定模板的 onRendered()
回调期间,其他 DOM 元素可能尚未准备好进行操作,并且 (b) 它使关注点分离和代码清晰度大大降低更难实现。
有没有办法使用 Meteor 的 Template.events
绑定(bind)这些事件,如果是的话,完成此操作的正确语法是什么?
谢谢。
最佳答案
如解决方案中所述,绑定(bind) UI 的最佳方法是使用 manuel:viewmodel
您将 UI 的状态保存在 JavaScript 对象中,并将 UI 元素绑定(bind)到该对象的属性。
可以找到文档 here
关于javascript - 在 Meteor Template.events 中绑定(bind) Semantic-UI 模块事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32885104/