角JS切换数据启用和禁用检查 [英] angular js toggle data enable and disable on check

查看:149
本文介绍了角JS切换数据启用和禁用检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个角应用程序,它具有以下切换表

I have the an angular app which has the following toggle table:

<tr ng-repeat="child in requirements">
    <td class="vcenter">
    <input type="checkbox" ng-checked="checkedfunction(child)" ng-click="toggleCheck(child)" ng-disabled="required == (planned + completed) && (selectedCourses.indexOf(child) == -1)" value=""/>
    {{child.course.subject}}-{{child.course.course_no}}
    </td>
    <td class="vcenter">{{child.course.course_name}}</td>}
    <td class="vcenter">3</td> 
</tr>

和控制器app.js具有以下功能:

And the controller app.js has the following function:

    $scope.toggleCheck = function (course) {
            //checkedfunction(course);
            if (($scope.selectedCourses.indexOf(course) === -1)) {
                $scope.selectedCourses.push(course);
                $scope.planned += 3;    
            } else {
                $scope.selectedCourses.splice($scope.selectedCourses.indexOf(course), 1);
                $scope.planned -= 3;
            }

            $scope.getPercentage();
    };

    $scope.checkedfunction = function(course){
        //$scope.requirementcoursename = [];
        //for(var i = 0; i < $scope.requirements.length; i++){
            $scope.coursedetail = course;
            $scope.requirementcoursename = ($scope.coursedetail.course.subject).concat("-",$scope.coursedetail.course.course_no);
            for(var j = 0; j < $scope.mpttdetails.length; j++){
                if($scope.requirementcoursename==$scope.mpttdetails[j].student_academic_credit.course_name){
                    return true;
                }
            }
            for(var k = 0; k < $scope.planneddetails.length; k++){
                if($scope.requirementcoursename==$scope.planneddetails[k].course_name){
                    return true;
                }
            }
        //} 

    }

在这里,如果课程如 checkedfunction看到,已经present中的任何数据阵列的切换将检查()

但我想知道是否有禁止在被检查的课程 mpttdetails 并保持 planneddetails方式启用?

But i would like to know if there is a way to disable the courses being checked in the mpttdetails and keep the planneddetails enabled?

我试图检查和禁用切换(随便怎么样我这样做了NG-选中),如果孩子是present在mpttdetails(即当在mpttdetails循环执行检查它返回true )。如果没有它只会保持选中并启用

i am trying to check and disable the toggle(just like how i am doing it in the ng-checked) if the child is present in mpttdetails(ie it returns true when the check is performed on the mpttdetails loop). If not it will just stay checked and enabled

推荐答案

将您的 mpttdetails 检查 checkFunction 的,创建一个新的范围功能:

Break your mpttdetails check out of checkFunction, creating a new scope function:

$scope.checkMpttdetails = function(course) {
    ...    
}

这样的话,你仍然可以从 checkedFunction

$scope.checkedfunction = function(course){
    ...
    if ($scope.checkMpttdetails) { return true }
    ...
}

而在使用它你的 NG-停用前pression

ng-disabled="(required == (planned + completed) && 
(selectedCourses.indexOf(child) == -1)) || checkMpttdetails(child)"

我知道有这将需要一些重构的其他详细信息(如:你怎么在 checkedFunction 的顶部使用传递的参数),但这些都留给你。

I realize that there are additional details that will require some refactoring (e.g. how you use the passed parameters at the top of checkedFunction), but those are left to you.

这篇关于角JS切换数据启用和禁用检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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