有谁知道如何在Meteor中使用Semantic-ui复选框(切换)?
<div class="ui toggle checkbox">
<input type="checkbox" name="public">
<label>Subscribe to weekly newsletter</label>
</div>
复选框/滑块在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'));
}
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句