【问题标题】:Semantic-ui checkbox in MeteorMeteor 中的 Semantic-ui 复选框
【发布时间】:2015-08-02 17:52:59
【问题描述】:
有人知道如何在 Meteor 中使用 Semantic-ui 复选框(切换)吗?
<div class="ui toggle checkbox">
<input type="checkbox" name="public">
<label>Subscribe to weekly newsletter</label>
</div>
复选框/滑块在 html 页面上可见,具有滑动效果,但我不明白如何针对控件进行编码。如何根据值设置选中/取消选中以及如何处理事件。
【问题讨论】:
标签:
checkbox
meteor
semantic-ui
【解决方案1】:
这就是我的做法:
Session.set('chosen', false);
Template.myTemplate.onRendered(function () {
var $elem = this.$('.checkbox');
// Use 'set unchecked' or 'set checked' instead of 'uncheck'/'check'
// to avoid triggering the callback.
// Set initial state here:
$elem.checkbox('set ' + (Session.get('chosen') ? 'checked' : 'unchecked'));
// Keep state synced with the session.
$elem.checkbox({
onChange: function () {
Session.set('chosen', !Session.get('chosen'));
}
});
});