Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs发出指令取消选中所有复选框_Angularjs - Fatal编程技术网

Angularjs发出指令取消选中所有复选框

Angularjs发出指令取消选中所有复选框,angularjs,Angularjs,您好,谢谢您关注我的问题 我正在创建一个简单列出父母及其子女的指令。每个父项都有一个复选框,允许用户打印确实选中的父项(例如:如果用户选中父项#1和#5,则只打印#1和#5)。我还有一个过滤器,允许用户“过滤”父母(超过100个) 问题在于复选框:我希望选择过滤器(下拉列表)时清除所有复选框。现在,如果用户检查父项#1和#5并过滤掉5,则#1保持选中状态。我正在下面添加我的代码。 非常感谢你帮助我 app.directive('isolateScopeWithController', funct

您好,谢谢您关注我的问题

我正在创建一个简单列出父母及其子女的指令。每个父项都有一个复选框,允许用户打印确实选中的父项(例如:如果用户选中父项#1和#5,则只打印#1和#5)。我还有一个过滤器,允许用户“过滤”父母(超过100个)

问题在于复选框:我希望选择过滤器(下拉列表)时清除所有复选框。现在,如果用户检查父项#1和#5并过滤掉5,则#1保持选中状态。我正在下面添加我的代码。 非常感谢你帮助我

app.directive('isolateScopeWithController', function () {

var controller = ['$scope', 'treeFactory', '$q', function ($scope, treeFactory, $q) {

    var vm = this;

    $scope.ocw = "";

    $scope.types = [
                   {description : "All Parent", type : 2},
                   {description : "True Parent", type : 1},
                   {description : "Parent", type : 0}
               ];

     $scope.$watch('selectedType', function(){          
        // I wish I would have this function working
        uncheckAll();

    })

   function uncheckAll() {
        // uncheck all the  check box currently checked 
        // cannot do it!
    }

    init();

    function init(){

        $scope.selectedType = "2";

        $scope.ocw = {
         "parents":[
         {name: "parent1", "type": 0, children: ["name": "child1", "name": "child2"]},
         {name: "parent2", "type": 0, children: ["name": "child3", "name": "child4"]},
         ...
         {name: "parent5", "type": 1, children: ["name": "child10", "name": "child11"]}
         ]
        }
    }
    ],

  template = '<div>'+
                 '<div>'+
                    '<select ng-model="selectedType" ng-change="update(selectedType)">'+
                        '<option ng-repeat="x in types" value="{{x.type}}">{{x.description}}</option>'+
                    '</select>'+                        
                 '</div>'+                      
                 '<div>'+
                    '<button type="button" class="btn btn-default btn-primary" ng-click="printParentschecked(ocw)"> <span class="glyphicon glyphicon-print"></span> Print Selected </button>'+
                 '</div>'+
             '</div>'+
                 '<div ng-repeat="parent in ocw.parents" class="col-sm-8">'+
                    '<div ng-if="filterType(parent.type)">'+    
                         '<div class="row">'+
                            '<div class="col-sm-8">'+
                                '<span>{{parent.name}}</span>'+
                            '</div>'+
                            '<div class="col-sm-2">'+
                                '<input type="checkbox" ng-model="parent.isOpenValue" ng-click="checked(parent.name)" >'+
                            '</div>'+
                         '</div>'+
                        '<div ng-repeat="org in parent.children" class="col-sm-8">'+
                            '{{children.name}}'+
                        '</div>'
                    '</div>'+       
                 '</div>'+

             '</div>';
  return {
      restrict: 'E', 
      replace: true,
      scope: {},
      controller: controller,
      template: template,   
      transclude: true,
      link: function(scope, element, attrs, transclude) {
                scope.printParentschecked = function(ocw){
                    // print the checked parents... I can do it!
                }
                scope.filterType = function(type) {
                    //it works, it checks the value selected in the drop down and the type of the parent
                    // if they match they are shown
                if (types === 1 && type === 1) {
                    return true;
                }
                ....


          }  
      }
  };
});
app.directive('isolateScopeWithController',函数(){
变量控制器=['$scope','treeFactory','$q',函数($scope,treeFactory,$q){
var vm=这个;
$scope.ocw=“”;
$scope.types=[
{说明:“所有父级”,类型:2},
{description:“真正的父级”,类型:1},
{说明:“父”,类型:0}
];
$scope.$watch('selectedType',function(){
//我希望这个功能能正常工作
取消勾选();
})
函数uncheckAll(){
//取消选中当前选中的所有复选框
//不行!
}
init();
函数init(){
$scope.selectedType=“2”;
$scope.ocw={
“父母”:[
{name:“parent1”,“type”:0,子项:[“name”:“child1”,“name”:“child2”]},
{name:“parent2”,“type”:0,子项:[“name”:“child3”,“name”:“child4”]},
...
{name:“parent5”,“type”:1,childs:[“name”:“child10”,“name”:“child11”]}
]
}
}
],
模板=“”+
''+
''+
“{x.description}}”+
''+                        
''+                      
''+
“打印所选内容”+
''+
''+
''+
''+    
''+
''+
“{{parent.name}}”+
''+
''+
''+
''+
''+
''+
“{{children.name}}”+
''
''+       
''+
'';
返回{
限制:'E',
替换:正确,
作用域:{},
控制器:控制器,
模板:模板,
是的,
链接:函数(范围、元素、属性、转置){
scope.printParentschecked=函数(ocw){
//打印检查过的父母…我能做到!
}
scope.filterType=函数(类型){
//它工作,它检查下拉列表中选择的值和父对象的类型
//如果它们匹配,则显示它们
if(类型===1&&type==1){
返回true;
}
....
}  
}
};
});
另外,可能真正的问题是我不太理解角度指令:(

试试这个:

  function uncheckAll() {
              angular.forEach(ocw.parents,function(parent,key){                  
                       parent.isOpenValue=false;        
                      }
            }

init()
定义之后似乎有语法错误-有
],
,可能是
}]
作为您的
控制器定义的结尾。这可能不会解决您的主要问题,但您仍然需要语法正确的代码,才能使任何解决方案真正起作用。回答得好!Sreehari!四行代码救了我一天!谢谢!