绑定语义-流星模板中的ui模块事件
Binding Semantic-UI module events in Meteor Template.events
不使用jQuery,我想用"Meteor-way"将回调绑定到语义ui模块,有点像Bootstrap 3允许的,例如:
Template.someTemplate.events({
'show.bs.dropdown .someDropdown': function () {
// official Bootstrap JS callback for the Dropdown module's show event
}
});
与语义ui,似乎我只能定义回调函数时使用jQuery绑定在包含模板的onRendered()
回调,例如:
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)它使关注点分离;代码清晰更难实现。
是否有一种方法来绑定这些事件使用流星的Template.events
,如果是这样,什么是正确的语法来完成这一点?
谢谢。
请参考此解决方案
如解决方案中所述绑定UI的最佳方法是使用manuel:viewmodel
将UI的状态保存在javascript对象中,并将UI元素绑定到该对象的属性。
文档可以在这里找到
我的解决方案
html<div class="ui search selection dropdown" id="dataDropdown">
<input type="hidden" name="applications">
<i class="dropdown icon"></i>
<div class="default text">Application</div>
<div class="menu" >
{{#each data}}
<div class="item" data-value={{id}}>
{{name}}
</div>
{{/each}}
</div>
</div>
js
//can catch 2 events when searching then clicking on a dropdown item.
//first event is the change of the input text. second event is the dropdown
//change. we only want the values associated with the dropdown change, thus
//we use the if check
change #appDropdown': function(event, template) {
if (event.target.type === 'text'){
return;
}
console.log(event.target.value);
}
相关文章:
- Template.subscriptionReady和语义UI Accordion模块
- 如何通过不同的方式从控制器加载ui.bootstrap模块
- 语义UI粘性模块不工作
- AngularJS - 如何从ui-router引用子模块控制器
- 使用 ui-view 导致无法实例化模块 ui.router
- 使用 ui 路由器时出错:“$injector:模块”
- 如何嵌套 React 组件/模块以分离 UI
- 如何使用角度模块“ui-route”在指令中查找模板URL,而不会在MVC .NET上出现错误
- 哪些jQuery UI模块是动画正常工作所必需的
- 未捕获错误:找不到从“ui/app”加载程序导入的模块“ember”.js:164
- tortoro:UI模块,用于包含缩小的javascript
- 版本0.9.0的UI.引导模块未捕获错误
- ui路由器添加模块
- AngularJS UI路由器赢得't识别模块上已定义的控制器
- 使用'时出错;ui.引导程序'和'720kb.datepicker'模块
- 绑定语义-流星模板中的ui模块事件
- jQuery-ui可排序可拖动模块遇到多个问题
- Angular UI树模块:移除的回调不起作用
- 模块化UI路由器
- AngularJS 1.5.4无法使用boostrap ui模块