Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.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 如何在AngularJS的ng repeat中动态格式化表格_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript 如何在AngularJS的ng repeat中动态格式化表格

Javascript 如何在AngularJS的ng repeat中动态格式化表格,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我有一个不同类型的项目列表,我想在表格中显示它们。 一种类型的项将有两列,而另一种类型的项只有一列。有没有关于如何有条件地更改标签上的colspan的建议 <div ng-init="items = [ {name:'item1', old:1, new:2}, {name:'item2', old:2, new:2}, {name:'item3', msg: 'message'}, {name:'item4', old:0, new:2} ]"&g

我有一个不同类型的项目列表,我想在表格中显示它们。 一种类型的项将有两列,而另一种类型的项只有一列。有没有关于如何有条件地更改标签上的colspan的建议

 <div ng-init="items = [
    {name:'item1', old:1, new:2}, 
    {name:'item2', old:2, new:2},
    {name:'item3', msg: 'message'},
    {name:'item4', old:0, new:2}
  ]">
  <table border=1>    
    <tr  ng-repeat="item in items" >                   
     <th>{{item.name}}</th>
     <td>{{item.old}}</td>  
     <td colspan='2'>{{item.msg}}</td>     
     <td>{{item.new}}</td>      
    </tr>              
 </table>

{{item.name}
{{item.old}
{{item.msg}
{{item.new}
下面是在JSFIDLE中使用的示例:


谢谢

您可以使用条件指令(如ng show)执行以下操作:

<table border=1>    
   <tr  ng-repeat="item in items" >                   
      <th>{{item.name}}</th>
      <td>{{item.old}}</td>  
      <td colspan="2" ng-show="item.type == 'typeA'">{{item.msg}}</td>
      <td ng-show="item.type == 'typeB'">{{item.msgB1}}</td>     
      <td ng-show="item.type == 'typeB'">{{item.msgB2}}</td>          
      <td>{{item.new}}</td>      
   </tr>              
</table>

{{item.name}
{{item.old}
{{item.msg}
{{item.msgB1}}
{{item.msgB2}}
{{item.new}
有关ng show的更多信息:


您的问题不清楚。我在项目中没有看到
类型
字段。你期望的结果是什么?为了完整性
ng,如果也是这样的话。你能把我的答案标记为有效吗?请关闭主题?