有人知道如何在 Meteor 中使用 Semantic-ui 复选框(切换)吗?
<div class="ui toggle checkbox">
<input type="checkbox" name="public">
<label>Subscribe to weekly newsletter</label>
</div>
复选框/ slider 在 html 页面上可见,具有滑动效果,但我无法理解如何针对该控件进行编码。如何根据值设置选中/未选中以及如何处理事件。
最佳答案
我就是这样做的:
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'));
}
});
});
关于checkbox - Meteor 中的语义 ui 复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31770497/