checkbox.js 427 B

123456789101112131415161718192021222324
  1. var _ = require('../../util')
  2. module.exports = {
  3. bind: function () {
  4. var self = this
  5. var el = this.el
  6. this.listener = function () {
  7. self.set(el.checked)
  8. }
  9. _.on(el, 'change', this.listener)
  10. if (el.checked) {
  11. this._initValue = el.checked
  12. }
  13. },
  14. update: function (value) {
  15. this.el.checked = !!value
  16. },
  17. unbind: function () {
  18. _.off(this.el, 'change', this.listener)
  19. }
  20. }