简体   繁体   English

Vue:选中/取消选中祖父母或父母时选中/取消选中复选框

[英]Vue: Check/uncheck checkbox when Grandparent or parent is checked/unchecked

So I am trying to check/uncheck a checkbox when grandparent or parent is checked/unchecked: 因此,当选中/取消选中祖父母或父母时,我会尝试选中/取消选中一个复选框:

new Vue({
  el: '.app',
  data: {
    grand_parent: false,
    parent: false
  }
})

However it's not working as can be seen here: 然而,它在这里看不到:

http://jsbin.com/yabewemimo/edit?html,js,output http://jsbin.com/yabewemimo/edit?html,js,output

What I am trying to acheive is: 我想要实现的目标是:

  • When grand-parent is checked/unchecked, it should affect direct children eg both parent and child 当选中/取消选中祖父母时,它应该影响直接的孩子,例如父母和孩子
  • When parent is checked/unchecked, it should affect child only 选中/取消选中父级时,它应仅影响子级

Thanks for the help 谢谢您的帮助

Your code is not working as per your expectations as you have a v-model on your parent, so your :checked property binding is not having an effect. 您的代码无法按照您的期望工作,因为您的父v-model上有v-model ,因此您的:checked属性绑定没有效果。

new Vue({
  el: '.app',
  data: {
    grand_parent: false,
    parent_proxy: false // Because it will cause a stack overflow if
  },                    // I reference this.parent in its own computed
  computed: {
    parent: {
      get () {
        return (this.grand_parent)
          ? true 
          : this.parent_proxy
      },
      set (val) {
        this.parent_proxy = val
      }
    }
  }
})

the working bin 工作

It looks like you'll have to watch it: 看起来你必须要看它:

  watch: {
    grand_parent: function (val) {
      if (val) this.parent = true;
    }
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 嵌套复选框:带有父母支票的已选中/未选中的孩子 - Nested Checkbox : Checked / Unchecked children with parent check jQuery复选框分组-至少单击一个子复选框时取消选中父级,选中所有子复选框时选中父级 - Jquery checkbox grouping - uncheck parent when at least one sub checkbox is clicked, check parent when all are checked vue - 取消选中父级时取消选中所有子复选框 - vue - uncheck all child checkboxes when parent is unchecked 如果未选中所有子项,请取消选中父复选框 - Uncheck parent checkbox if all child is unchecked AG-GRID-ANGULAR - 如果选中/取消选中单元格渲染器中的所有复选框,如何选中/取消选中标题组件中的复选框? - AG-GRID-ANGULAR - How to check/uncheck checkbox in header component if all checkboxes in the cell renderers are checked/unchecked? 在 Vue 3 中选中和取消选中复选框时,如何执行两种不同的方法? - How to execute two different methods for when a checkbox is checked and unchecked in Vue 3? 复选框:取消选中时选中另一个 - Checkbox: uncheck when on another is checked 选中另一个复选框后,取消选中该复选框 - Uncheck a checkbox when another is checked jQuery - 选中CHECK ALL时取消选中其他复选框 - jQuery - Unchecked other checkbox when CHECK ALL is checked 取消选中复选框时如何禁用PHP禁用和清除文本框。 选中/取消选中复选框,具体取决于数据库 - How to disable anPHP disable and clear textbox when checkbox is unchecked. Check/uncheck checkbox depending on database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM