Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.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
Javascript 我想用angular对表格标题和正文进行一些验证_Javascript_Angularjs_Html - Fatal编程技术网

Javascript 我想用angular对表格标题和正文进行一些验证

Javascript 我想用angular对表格标题和正文进行一些验证,javascript,angularjs,html,Javascript,Angularjs,Html,我想对一个表进行验证,在任何列单元格中删除任何内容之前,用户都不能在该单元格标题中删除任何内容。但我不知道如何在每个列的表头和单元格之间建立连接 这是我的控制器: angular.module('myApp', []).controller('myCtrl', function($scope) { $scope.tableSelection = {}; $scope.tableInputColSelection={};//added for ccgbase 2251

我想对一个表进行验证,在任何列单元格中删除任何内容之前,用户都不能在该单元格标题中删除任何内容。但我不知道如何在每个列的表头和单元格之间建立连接

这是我的控制器:

angular.module('myApp', []).controller('myCtrl', function($scope) {
      $scope.tableSelection = {};
      $scope.tableInputColSelection={};//added for ccgbase 2251
    $scope.tableOutputColSelection={};
    $scope.output_columns=[1];
    $scope.input_columns=[1];
      $scope.data = [];
      $scope.rows = [1, 2, 3]; 

      $scope.removeSelectedItems = function(){
       // $scope.rows = $scope.rows.filter(function(item, index){
         // return !($scope.tableSelection[index] !== undefined && $scope.tableSelection[index]); 
       if(Object.keys($scope.tableSelection).length>0){
                                 for (var i = $scope.rows.length - 1; i >= 0; i--) {
                                  if ($scope.tableSelection[i]) {
                                    //delete row from data
                                      if($scope.rows.length>1){
                                      $scope.rows.splice(i, 1);
                                      }

                                     delete $scope.tableSelection[i];
                                }
                                 }
                                }
                                if(Object.keys($scope.tableInputColSelection).length>0){
                                    for (var i = $scope.input_columns.length - 1; i >= 0; i--) {
                                      if ($scope.tableInputColSelection[i]) {
                                        //delete row from data
                                          if($scope.input_columns.length>1){
                                            $scope.input_columns.splice(i, 1);
                                          }
                                        delete $scope.tableInputColSelection[i];
                                      }
                                }

                                }
                                if(Object.keys($scope.tableOutputColSelection).length>0){
                                    for (var i = $scope.output_columns.length - 1; i >= 0; i--) {
                                      if ($scope.tableOutputColSelection[i]) {
                                        //delete row from data
                                          if($scope.output_columns.length>1){
                                            $scope.output_columns.splice(i, 1);
                                          }
                                        delete $scope.tableOutputColSelection[i];
                                      }
                                    }
                                }





      }
      $scope.addNewRow = function() {
        //set row selected if is all checked

        $scope.rows.push({
          id: $scope.rows.length,
          name: 'Name ' + $scope.rows.length
        });
      };
     $scope.addInput= function () {
                                for(var i=0;i<1;i++){
                                    $scope.input_columns.push({
                                        id:$scope.input_columns.length,
                                        name: 'Name'+$scope.input_columns.length
                                    });
                                    }
                            },

         $scope.addOutput= function () {
                                for(var i=0;i<1;i++){
                                    $scope.output_columns.push({
                                        id:$scope.output_columns.length,
                                        name:'Name'+$scope.output_columns.length
                                    });
                                    }
                            }

This is the plunker link:
http://plnkr.co/edit/IpUjN5wiwv3q8XT2y864?p=preview
angular.module('myApp',[]).controller('myCtrl',function($scope){
$scope.tableSelection={};
$scope.tableInputColSelection={};//为ccgbase 2251添加
$scope.tableOutputColSelection={};
$scope.output_columns=[1];
$scope.input_columns=[1];
$scope.data=[];
$scope.rows=[1,2,3];
$scope.removeselectedems=函数(){
//$scope.rows=$scope.rows.filter(函数(项,索引){
//return!($scope.tableSelection[index]!==undefined&&$scope.tableSelection[index]);
if(Object.keys($scope.tableSelection).length>0){
对于(变量i=$scope.rows.length-1;i>=0;i--){
如果($scope.tableSelection[i]){
//从数据中删除行
如果($scope.rows.length>1){
$scope.行拼接(i,1);
}
删除$scope.tableSelection[i];
}
}
}
if(Object.keys($scope.tableInputColSelection).length>0){
对于(变量i=$scope.input\u columns.length-1;i>=0;i--){
if($scope.tableInputColSelection[i]){
//从数据中删除行
if($scope.input\u columns.length>1){
$scope.input_columns.拼接(i,1);
}
删除$scope.tableInputColSelection[i];
}
}
}
if(Object.keys($scope.tableOutputColSelection).length>0){
对于(变量i=$scope.output\u columns.length-1;i>=0;i--){
if($scope.tableOutputColSelection[i]){
//从数据中删除行
if($scope.output\u columns.length>1){
$scope.output_columns.拼接(i,1);
}
删除$scope.tableOutputColSelection[i];
}
}
}
}
$scope.addNewRow=函数(){
//如果全部选中,则将行设置为选中
$scope.rows.push({
id:$scope.rows.length,
名称:'name'+$scope.rows.length
});
};
$scope.addInput=函数(){

对于(var i=0;i我不知道复杂度是如何成为你的目标的。但是下面的想法可能会对你有所帮助

如果数组如下所示,则可以轻松地进行验证

Headers=[Header1,Header2,Header3,Header4]

Header1ColumnValues=这些是值的数组。列
=这些是值的数组

纵队= [[header1列值]、[header2列值]、[header3列值]、[header4列值]]

如果要访问列1和标题1,则可以访问

标题[0],列[0],对于2n,标题[1],列[1]


但是这个解决方案在按顺序输入数据时有效,假设在第5列第4行删除数据,那么如何识别单元格的索引。您可以从ng repeat获取索引,并为on drop提供回调函数。将此ng repeat索引传递给此回调函数。然后您将获得列的索引。行将被标识为b基于哪个位置的数据。希望这能对你有所帮助。我尝试了一些解决方案,但在drop函数中没有得到$index值。它在html页面本身上给出了$index未定义的错误。你能帮助我在任何元素被DROPPED时如何得到每个单元格的索引吗?我在输入标题中添加了我的plunker,我没有添加$index on drop,因此它可以工作。在输出标题上,它不允许删除。我不知道如何在drop方法中传递$index。在复选框上,由于复选框的选择,我能够获得索引,并且能够根据该选择删除整列和整行。但不知道如何在删除任何元素时获得索引。