[英]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: 我想要实现的目标是:
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
}
}
}
})
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.