我怎样才能把多个值NG-残疾人的角度JS? [英] How can I put multiple values for ng-disabled in angular js?

查看:96
本文介绍了我怎样才能把多个值NG-残疾人的角度JS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么可以把多个值NG-残疾人的角度JS?

How can I put multiple values for ng-disabled in angular js?

我的问题是这个JS如下解释小提琴:
http://jsfiddle.net/FJf4v/10/

My problem is explained with this following JS fiddle: http://jsfiddle.net/FJf4v/10/

    <div ng-app>
<div ng-controller="myCnt">

    <h3>A ->> <input type="checkbox" ng-model="check"> </input></h3>
    <h3>B ->> <input type="checkbox" ng-model="check"> </input></h3>  

    <br/>
    <input type="checkbox" ng-disabled="check">Chkbox1 to be disabled</input>
    <input type="checkbox" ng-disabled="check">Chkbox2 to be disabled</input>
    <hr/>
</div>
</div>

Javascript:
function myCnt($scope) {
//
}

在此小提琴,还有标有A,B,Chkbox1和Chkbox2共4复选框。
我所寻找的是检查A和B的其中一个复选框后禁用这两个chkbox1和chkbox2。然而,它做半途而废。如果你点击了A或B,这两个按钮都得到检查和下方chkboxes越来越禁用。但是,我不想得到遏制A和B的复选框,如果我只需点击其中任何一个。

In this fiddle, there are total 4 check boxes labeled as A, B, Chkbox1 and Chkbox2. What I am looking for is to disable both chkbox1 and chkbox2 after checking one of A and B checkboxes. However, its done halfway. If you click on either A or B, both these buttons are getting checked and below chkboxes are getting disabled. But, I dont want to get checked both A and B checkboxes if I just click on any one of them.

我希望,你会得到我的问题。

I hope, you will get my question.

感谢您!

推荐答案

所以,我在评论中说,如果你想用一个很长的复选框列表来实现这一点,你可以试试这个方法:(是这例如,很长是指10)

So, as I said in the comments, if you want to achieve this with a very long list of checkboxes, you can try this way : (yeah for this example "very long" means 10)

该机型结果
您可以使用一个简单的对象将包含复选框的所有值,我该用NG重复做,但它可以是任何东西,只要使用同一个迭代的对象:

The models
You can use a simple object which will contain all the values of the checkboxes, I did this using a ng-repeat, but it could be anything, just use the same iterable object :

<input type="checkbox" ng-repeat="nb in [1,2,3,4,5,6,7,8,9,10]" ng-model="checkModels[nb]" /></h3>

这个对象是在控制器初始化,我没有指定任何值,但例如可以在这里设置一些复选框:

This object is initialized in the controller, I didn't specify any value, but you could for example set some checkboxes here :

$scope.checkModels={};

的禁用功能结果
这里没有什么很困难的,而不是一个长长的清单,||值,我们将遍历模型,并尽快返回true,我们发现一个选中的框:

The disabling function
Nothing very difficult here, instead of a long list of || values, we will iterate through the models and return true as soon as we find a checked box :

    $scope.isThisDisabled=function(){
     for(var i in $scope.checkModels)
     {
         if($scope.checkModels[i])
             return true             
     }
    return false;
}

然后,我们可以在HTML使用此功能:

Then, we can use this function in the HTML :

<input type="checkbox" ng-disabled="isThisDisabled()">Chkbox1 to be disabled</input>

修改后的小提琴测试: http://jsfiddle.net/DotDotDot/FJf4v/12/

有乐趣

这篇关于我怎样才能把多个值NG-残疾人的角度JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆