如何查找子项和禁用复选框?

时间:2015-04-17 19:04:34

标签: javascript arrays angularjs foreach kendo-ui

如果选择了一位家长,我想禁用其他家长及其子女。我怎样才能完成这项任务。我正在使用AngularJS进行此实现。

到目前为止尝试过代码..

HTML

<div id="treeViewDisplay4" class="dropdown-menu multi-level"
    ng-style="nonPersistentProcess.geoLocationStyle">
    <div kendo-tree-view="geoLocationTree"
        k-data-source="geoLocationDataSource"
        options="geoLocationTreeOptions"
        k-on-expand="onGeoExpand(kendoEvent)"
        k-rebind="nonPersistentProcess.selectedTypeGEO">
    </div>
</div>

main.js

 var getChildren = geoLocation.children;
 $.each(geoLocation.children,function(index,location) {
   var data = geoLocation.children.data;
   console.log(JSON.stringify(data));
   for (var i =0; i<data.length; i++) {
     if (data[i] !== geoLocation.id) {
       $scope.geoLocationTree.expand(".k-item");
       $scope.geoLocationTree.collapse(".k-item");
       var disableChildren = 'disabled' + data.id;
       // Get the model
       var model = $parse(disableChildren);
       // Assigns a value to it
       model.assign($scope, true);
       }
     }
   });

data.js

[
    {
        "id": 67000,
        "text": "Americas",
        "items": [
            {
                "id": 5677,
                "text": "Anguilla",
                "items": null
            },
            {
                "id": 5678,
                "text": "Antarctica",
                "items": null
            },
            {
                "id": 5679,
                "text": "Antigua And Barbuda",
                "items": null
            }
        ]
   }
]

1 个答案:

答案 0 :(得分:0)

我能够找到上述问题的解决方案,我在循环中实现了循环,实现了魔法......感谢您的帮助

if (geoLocation.id === 5657){
              var getParent = geoLocation.parent();
              $.each(geoLocation.parent(),function(index,location) {
                if (location.id !== geoLocation.id) {
                  $.each(location._childrenOptions.data.items,function(index,child){
                    var disableChildId = 'disabled' + child.id;
                    var model = $parse(disableChildId);
                      model.assign($scope, false);
                  })
                  var disableItemId = 'disabled' + location.id;
                  // Get the model
                  var model = $parse(disableItemId);
                  // Assigns a value to it
                  model.assign($scope, false);
                }
              });
            }