【问题标题】: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'));
        }
      });
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-09
      • 2017-02-11
      • 1970-01-01
      • 2016-03-29
      • 2018-07-16
      • 2023-03-06
      • 2016-04-27
      • 1970-01-01
      相关资源
      最近更新 更多