Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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
Angularjs 使用ng repeat from数组创建HTML表_Angularjs_Html Table_Angularjs Ng Repeat - Fatal编程技术网

Angularjs 使用ng repeat from数组创建HTML表

Angularjs 使用ng repeat from数组创建HTML表,angularjs,html-table,angularjs-ng-repeat,Angularjs,Html Table,Angularjs Ng Repeat,有人能帮我用Angular JS ng repeat创建HTML表吗。我有如下的数组 cyclename = [cycle1,cycle2,cycle3] passValue = [2,5,250] 使用这些,我想生成HTML表作为 <table> <tr> <td>cycle1</td> <td>2</td> </tr> <tr> <td>cycle

有人能帮我用Angular JS ng repeat创建HTML表吗。我有如下的数组

cyclename = [cycle1,cycle2,cycle3]
passValue = [2,5,250]
使用这些,我想生成HTML表作为

<table>
  <tr>
    <td>cycle1</td>
    <td>2</td>
  </tr>
  <tr>
    <td>cycle2</td>
    <td>5</td>
  </tr>
  <tr>
    <td>cycle3</td>
    <td>250</td>
  </tr>
</table>

循环1
2.
周期2
5.
周期3
250
我已经试过了,但没有成功

<table class="table">
    <tr ng-repeat="x in cyclename">
    <td>{{x}}</td>
    </tr>
    <tr ng-repeat="x in passValue">
    <td>{{x}}</td>
    </tr>
 </table>

{{x}
{{x}

将数组修改为行对象数组

fullArr = [{cyclename :'cycle1',passValue : '2' },{cyclename :'cycle2',passValue : '5' },{cyclename :'cycle3',passValue : '250' }]

 <table class="table">
    <tr ng-repeat="x in fullArr">
    <td>{{x.cyclename}}</td>
    <td>{{x.passValue}}</td>
    </tr> 
 </table>
fullArr=[{cyclename:'cycle1',passValue:'2'},{cyclename:'cycle2',passValue:'5'},{cyclename:'cycle3',passValue:'250'}]
{x.cyclename}
{{x.passValue}}

使用键值对合并两个数组并使用ng repeat

cyclename = [cycle1,cycle2,cycle3]
passValue = [2,5,250]

to 

mergerArr=[{
             key:cycle1,
             value:2
            },{
             key:cycle2,
             value:5
           }]
Html将如下所示

<table class="table">
<tr ng-repeat="x in mergerArr">
<td>{{x.key}}</td>
<td>{{x.value}}</td>
</tr>
</table>

{{x.key}}
{{x.value}}

这里是使用$scope的最简单方法,请参阅下面的代码

控制器

 $scope.cyclename = ["cycle1","cycle2","cycle3"]
 $scope.passValue = [2,5,250]
模板

<table>
 <tr ng-repeat="x in cyclename">
   <td>{{x}}</td>
   <td>{{passValue[$index]}}</td>
 </tr>

{{x}
{{passValue[$index]}

希望这将帮助您

简单的解决方案:

<table>
    <tr ng-repeat="i in [0,1,2]">
        <td>{{cyclename[i]}}</td>
        <td>{{passValue[i]}}</td>
    </tr>
</table>

请检查所需的结果html结构?@Icycool请告诉我html结构有什么问题?您的代码正在生成
x3x2
,而不是按照请求生成
x2x3
OP@Icycool谢谢。我用2种表格结构更新了plunker。
$scope.fullArr = cyclename.map(function(item, i) {
  return {
    cyclename: item,
    passValue: passValue[i]
  }
})