复选框ng-model未更改

时间:2017-02-17 00:50:37

标签: javascript angularjs

http://jsfiddle.net/ADukg/10211/

<label class="radio-inline" style="padding-left: 0px; display: block;">
    <input type="checkbox" ng-model="settings_channel" ng-checked="permission.settings.channel.ADMIN" ng-disabled="permission.settings.channel.ADMIN">A
</label>
<label class="radio-inline" style="padding-left: 0px; display: block;">
    <input type="checkbox" ng-model="permission.settings.channel.READ" ng-checked="settings_channel || permission.settings.channel.ADMIN" ng-disabled="permission.settings.channel.ADMIN">B
</label>
<label class="radio-inline" style="padding-left: 0px; display: block;">
    <input type="checkbox" ng-model="permission.settings.channel.WRITE" ng-checked="settings_channel || permission.settings.channel.ADMIN" ng-disabled="permission.settings.channel.ADMIN">C
</label>
<label class="radio-inline" style="padding-left: 0px; display: block;">
    <input type="checkbox" ng-model="permission.settings.channel.ADMIN" ng-checked="settings_channel">D
</label>

我希望当用户检查A或D时,B和C被禁用。

但该来源不会执行。

如果我选择D,我可以看到我想要的东西。

但是当我选择A时,D值不会改变,因此B和C不会被禁用。

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

试试这个:

<label class="radio-inline" style="padding-left: 0px; display: block;">
    <input type="checkbox" ng-model="settings_channel" ng-checked="permission.settings.channel.ADMIN" ng-disabled="permission.settings.channel.ADMIN">A
</label>
<label class="radio-inline" style="padding-left: 0px; display: block;">
    <input type="checkbox" ng-model="permission.settings.channel.READ" ng-checked="settings_channel || permission.settings.channel.ADMIN" ng-disabled="permission.settings.channel.ADMIN || settings_channel">B
</label>
<label class="radio-inline" style="padding-left: 0px; display: block;">
    <input type="checkbox" ng-model="permission.settings.channel.WRITE" ng-checked="settings_channel || permission.settings.channel.ADMIN" ng-disabled="permission.settings.channel.ADMIN || settings_channel">C
</label>
<label class="radio-inline" style="padding-left: 0px; display: block;">
    <input type="checkbox" ng-model="permission.settings.channel.ADMIN" ng-checked="settings_channel">D
</label>

我添加了A选项|| settings_channelAD相同,假设settings_channel是一个布尔值,它必须在复选框。