Dev*_*r52 8 javascript json angularjs
我有一个json,在这个json里面有一个我要迭代的数组<td>
.我的功能就像我必须根据用户输入创建一个表.用户提供行数,输入列和输出列的输入.所以我有三个数组,即$ rootScope.input_columns,$ rootScope.output_columns和$ rootScope.rows,它们包含用户提供的用于创建表的数据.现在在input_columns中有一个数组,其中包含我需要在行单元格上显示的一些信息.但是使用我目前的代码,它给了我空白行.
控制器:
var app = angular.module('rulesApp');
app.controller('myController2', ['$scope', '$rootScope',function($scope, $rootScope){
var inputcol=[];
$rootScope.input_col=$scope.no_of_input;
$rootScope.output_col=$scope.no_of_output;
$rootScope.rows=$scope.no_of_row;
for(var i=0;i<$rootScope.input_col;i++){
inputcol.push({
id: inputcol.length,
dropped: false,
dataType:'',
name:'',
type:'input',
path:'',
rowCellValue:[],
rowCellValueOutput:[]
});
}$rootScope.input_columns=inputcol;//here i get input_columns json, Similarly json are made for output_columns and rows
$scope.statementSelected = function(branch, selected_branches) {
if(branch.selected) {
for(var i = 0; i < $rootScope.input_columns.length; i++) {
//Here i add an array inside input_columns.rowCellValue $rootScope.input_columns[i].rowCellValue.push($rootScope.rows[i].rowCellValue);
}
})
Run Code Online (Sandbox Code Playgroud)
添加input_columns的结构
这是我的HTML代码:
<tbody>
<tr ng-repeat="row in rows"><!--It iterates on row json -->
<td><input type="checkbox"></td>
<!--Here i want that in row cells input_columns.rowCellValue data gets populate on row cell for input column -->
<td ng-repeat="col in input_columns.rowCellValue">{{(col == "") && "<enter data>" || (col.split("/")[3])}}</td>
<!--Here i want that in row cells output_columns.rowCellValueOutput data gets populate on row cell for output column -->
<td ng-repeat="col in output_columns.rowCellValueOutput" ng-click="openDialog($event)">{{(col == "") && "<enter data>" || (col.split("/")[3])}}</td>
</tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)
请任何人帮助我完成这项任务.是否有一个问题,我没有迭代input_columns所以我没有得到input_columns.rowCellValue值.如何在表列中获取input_columns.rowCellValue的值?无论如何,我可以使用两个ng重复,第一次ng-repeat我可以获得input_column值[col_input_column]和第二次ng-repeat我可以获得rowCellValue [col.rowCellValue中的单元格].
我正在尝试一些解决方案,并想出了一种访问rowCellValue的方法:
这是修改后的html代码
<tbody>
<tr ng-repeat="row in rows"><!--It iterates on row json -->
<td><input type="checkbox"></td>
<!--Here i want that in row cells input_columns.rowCellValue data gets populate on row cell for input column -->
<!--here with $index i am getting first value of rowCellValue in entire column can i iterate it with using rows length -->
<td ng-repeat="col in input_columns">{{(col.rowCellValue[$index] == "") && "<enter data>" || (col.rowCellValue[$index].split("/")[3])}}</td>
<!--Here i want that in row cells output_columns.rowCellValueOutput data gets populate on row cell for output column -->
<td ng-repeat="col in output_columns" ng-click="openDialog($event)">{{(col.rowCellValueOuput[$index] == "") && "<enter data>" || (col.rowCellValueOutput[$index].split("/")[3])}}</td>
</tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)
我可以用行长而不是$ index迭代col.rowCellValueOutput [$ index]吗?并为每一列.如果是,请为此提出一些建议.
我找到了解决我的问题的方法:
<td ng-repeat="col in input_columns" title="" id="{{col}}">{{(col.rowCellValue[$parent.$index] == "") && "<enter data>" || (col.rowCellValue[$parent.$index].split("/")[3])}}</td>
Run Code Online (Sandbox Code Playgroud)
在控制器中,json 的结构如下:
input_column({
rowCellValue[
0:dic2317/fdgdfg3535/accViolation
1:dic2317/sdg3436dg/driver
})
Run Code Online (Sandbox Code Playgroud)
我使用 $parent.$index 来迭代行索引。
归档时间: |
|
查看次数: |
452 次 |
最近记录: |