Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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 HTML表格中的显示对象ng repeat-角度_Javascript_Angularjs_Loops_Grid_Angularjs Ng Repeat - Fatal编程技术网

Javascript HTML表格中的显示对象ng repeat-角度

Javascript HTML表格中的显示对象ng repeat-角度,javascript,angularjs,loops,grid,angularjs-ng-repeat,Javascript,Angularjs,Loops,Grid,Angularjs Ng Repeat,我的物体看起来像这样 Object 207T : Object metal : 1 steel : 2 205T : Object metal : 1 steel : 3 208T : Object metal : 1 steel : 3 209T : Object metal : 0 steel : 9 现在我需要以下面的格式显

我的物体看起来像这样

Object
    207T : Object
        metal : 1
        steel : 2
    205T : Object
        metal : 1
        steel : 3
    208T : Object
        metal : 1
        steel : 3
    209T : Object
        metal : 0
        steel : 9   
现在我需要以下面的格式显示这个对象

207T, 205T, 208T, 209T  should be in table heading which is fine

<tr>
    <th></th>
    <th></th>
    <th ng-repeat="(key, value) in mainObj">{{key}}</th>
</tr>
207T、205T、208T、209T应该在表格标题中,这是可以的
{{key}}
然后格式应该是


如何为要将对象转换为数组的标题实现此操作:

// inside controller
mainObjArray = Object.keys(mainObj); // ['207T', '205T', '208T', '209T']
//标题html

<tr>
     <th ng-repeat="key in mainObjArray">{{key}}</th>
</tr>
然后是body表:

<tbody>
  <tr ng-repeat="item in mainObjValues">
   <td>{{item.metal}}</td>
   <td>{{item.steel}}</td>
   ....
  </tr>
</tbody>

{{item.metal}}
{{item.steel}}
....

对于标头,您需要将对象转换为数组:

// inside controller
mainObjArray = Object.keys(mainObj); // ['207T', '205T', '208T', '209T']
//标题html

<tr>
     <th ng-repeat="key in mainObjArray">{{key}}</th>
</tr>
然后是body表:

<tbody>
  <tr ng-repeat="item in mainObjValues">
   <td>{{item.metal}}</td>
   <td>{{item.steel}}</td>
   ....
  </tr>
</tbody>

{{item.metal}}
{{item.steel}}
....

我们无法按列创建表,因此在这种情况下,最好和最干净的方法是过滤掉行值并在视图中使用它们。所以 内部控制器

app.controller(['$scope', function($scope){
  $scope.object= values;

  $scope.valuesMetal= [];
  $scope.valuessteel = [];
  // initializing row values for use in the using in view

  angular.forEach(values, function(value, key) {
     $scope.valuesMetal.push(value.metal );
     $scope.valuessteel.push(value.metal );
  }); 
}]);
在视图中,我们只显示我们的值

<tr>
    <th ng-repeat="(key, value) in mainObj">{{key}}</th>
</tr>

<tr>
    <td >Metal</td>
    <td  ng-repeat="(key, value) in valuesMetal" >{{value}}</td>

</tr>

<tr>
    <td >steel</td>
    <td  ng-repeat="(key, value) in valuessteel" >{{value}}</td>

</tr>

<div>

{{key}}
金属
{{value}}
钢
{{value}}

我们无法按列创建表,因此在这种情况下,最好和最干净的方法是过滤掉行值并在视图中使用它们。所以 内部控制器

app.controller(['$scope', function($scope){
  $scope.object= values;

  $scope.valuesMetal= [];
  $scope.valuessteel = [];
  // initializing row values for use in the using in view

  angular.forEach(values, function(value, key) {
     $scope.valuesMetal.push(value.metal );
     $scope.valuessteel.push(value.metal );
  }); 
}]);
在视图中,我们只显示我们的值

<tr>
    <th ng-repeat="(key, value) in mainObj">{{key}}</th>
</tr>

<tr>
    <td >Metal</td>
    <td  ng-repeat="(key, value) in valuesMetal" >{{value}}</td>

</tr>

<tr>
    <td >steel</td>
    <td  ng-repeat="(key, value) in valuessteel" >{{value}}</td>

</tr>

<div>

{{key}}
金属
{{value}}
钢
{{value}}
角度模块(“应用程序”,[]) .controller(“ctrl”,函数($scope){ var sampleObj={ “207T”:{ “金属”:1, “钢”:2 }, “205T”:{ “金属”:1, “钢”:3 }, “208T”:{ “金属”:1, “钢”:3 }, “209T”:{ “金属”:0, “钢”:9 } } $scope.metal=[]; $scope.steel=[] $scope.keys=Object.keys(sampleObj); 角度。forEach(采样对象,函数(对象){ $scope.metal.push(obj.metal); $scope.steel.push(obj.steel); }); })

{{item}}
金属
{{item}}
钢
{{item}}
角度模块(“应用程序”,[]) .controller(“ctrl”,函数($scope){ var sampleObj={ “207T”:{ “金属”:1, “钢”:2 }, “205T”:{ “金属”:1, “钢”:3 }, “208T”:{ “金属”:1, “钢”:3 }, “209T”:{ “金属”:0, “钢”:9 } } $scope.metal=[]; $scope.steel=[] $scope.keys=Object.keys(sampleObj); 角度。forEach(采样对象,函数(对象){ $scope.metal.push(obj.metal); $scope.steel.push(obj.steel); }); })

{{item}}
金属
{{item}}
钢
{{item}}

这其实很简单

    <table>
    <tr>    
        <th></th>
        <th ng-repeat="(key, value) in mainObj">{{key}}</th>
    </tr>

{{key}}
在这里,您在th中重复ng,将显示207t、205T等

    <tr ng-repeat="item in items track by $index">    
        <td ng-repeat="item1 in item track by $index">{{item[$index]}}</td>            
    </tr>

{{item[$index]}

在这里,您必须
ng重复tr
,这样它将显示
金属
。然后每个
td
u必须
ng repeat
,并且应该显示索引
项[$index]

这实际上很简单

    <table>
    <tr>    
        <th></th>
        <th ng-repeat="(key, value) in mainObj">{{key}}</th>
    </tr>

{{key}}
在这里,您在th中重复ng,将显示207t、205T等

    <tr ng-repeat="item in items track by $index">    
        <td ng-repeat="item1 in item track by $index">{{item[$index]}}</td>            
    </tr>

{{item[$index]}
在这里,您必须
ng重复tr
,这样它将显示
金属
。然后每个
td
u必须
ng repeat
,并应显示索引
项[$index]