vue.js选中动态绑定的radio的指定项

如何选中radio的某一项
这里写图片描述

绑定的数据和上文的model是一致的,选中radio或者checkbox需要注意的是:

不管 你的checked属性值是true或者false,他都会选中。

选中不选中,不是看checked的属性值,而是看有没有checked这个属性,所以,动态选中,不用v-model,也不用checked=’true’,判断是否需要渲染checked这个属性就好了.

view 改一下:

<input type='radio' :name='groupName' :checked='option.checked'>{{option.text}}

:checked=’option.checked’ 如果option.checked为true,他就渲染checked这个属性,否则input元素没有这个属性。
这样绑定后,我们在vue的methods里面设置,把当前索引的radio绑定model的checked属性设置为true,其他的必须设置为false,这样才和上面的绑定对应,不然全是true了,绑定就会有问题了。

checkOption: function (e, optionIndex) {  
        $.each(vm.options, function (index, item) {  
            item.checked = false;                                                     
        });  
        vm.options[optionIndex].checked = true;  
    }  

转自:http://blog.csdn.net/q646926099/article/details/72841044

猜你喜欢

转载自blog.csdn.net/zbx931197485/article/details/79615082