我正在处理Angular JS任务,其中我需要从文本框中获取输入,并形成具有两个输入字段的行。输入该值时,形成了两个输入字段。应形成一个行和列的表。这是小提琴链接
https://jsfiddle.net/iamsaisanthosh/r1zync3g/
var app = angular.module('app', []);
app.controller('ctrl', function($scope) {
$scope.table = [];
$scope.cols = [];
$scope.rows = [];
$scope.arr = [];
$scope.arh = [];
$scope.trr = [];
$scope.makeArray = function() {
$scope.trr.length = 0;
for (var k = 0; k < parseInt($scope.table); k++) {
$scope.trr.push(k);
}
$scope.arr.length = 0;
for (var i = 0; i < parseInt($scope.rows); i++) {
$scope.arr.push(i);
}
$scope.arh.length = 0;
for (var j = 0; j < parseInt($scope.cols); j++) {
$scope.arh.push(j);
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="ctrl">
<input ng-model="table" type="text" ng-change="makeArray()" />
<table>
<tr ng-repeat="o in trr">
<td> <input ng-model="rows[$index]" type="text" ng-change="makeArray()" />
</td>
<td> <input ng-model="cols[$index]" type="text" ng-change="makeArray()" /></td>
</tr>
</table>
<div>
<table>
<tr ng-repeat="o in arr">
<td ng-repeat="o in arh">Col</td>
</tr>
</table>
</div>
</div>
</div>
我可以从文本框中获取输入并形成行。在形成的输入字段中输入值时,将形成具有输入值的表。表格仅适用于第一行输入值问题是我不能这样做超过一行
无法为第二行输入值表格表在上述小提琴中在文本字段中输入22行将与两个输入字段形成在第一行输入字段中分别输入3和4您可以看到一个带有3行和4列的表格当我在第二行中输入值时,我需要同样的事情第二个表应形成
//This piece is wrong right, $scope.rows, $scope.cols are not Strings/Numbers they are arrays and suppose to contain each tabs rows and columns index wise.
$scope.arr.length = 0;
for (var i = 0; i < parseInt($scope.rows); i++) {
$scope.arr.push(i);
}
$scope.arh.length = 0;
for (var j = 0; j < parseInt($scope.cols); j++) {
$scope.arh.push(j);
}
var app = angular.module('app', []);
app.controller('ctrl', function($scope) {
$scope.table = 0;
$scope.cols = [];
$scope.rows = [];
$scope.makeArray = function() {
if ($scope.table) {
return new Array(parseInt($scope.table));
} else {
return new Array(0);
}
}
$scope.getRowsCount = function ($index) {
if ($scope.rows[$index]) {
return new Array(parseInt($scope.rows[$index]));
} else {
return new Array(0);
}
}
$scope.getColsCount = function ($index) {
if ($scope.cols[$index]) {
return new Array(parseInt($scope.cols[$index]));
} else {
return new Array(0);
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="ctrl">
<input ng-model="table" type="text" />
<table>
<tr ng-repeat="t in makeArray() track by $index">
<td> <input ng-model="rows[$index]" type="text" />
</td>
<td> <input ng-model="cols[$index]" type="text" /></td>
</tr>
</table>
<div>
<table ng-repeat="t in makeArray() track by $index">
<tr ng-repeat="r in getRowsCount($index) track by $index">
<td ng-repeat="c in getColsCount($parent.$index) track by $index">Col</td>
</tr>
</table>
</div>
</div>
</div>