源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

angular ng-repeat数组中的数组实例

  • 时间:2020-03-09 00:37 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:angular ng-repeat数组中的数组实例
//先定义一个数组 [b]anular代码: [/b]
var app = angular.module('serApp', []); 

app.controller('indexCtrl', function($scope, $http) 
{ $scope.arrs = [{

<BR>                   n:'a'; 
        arr:['1','2','1'] 
      },{<BR><BR>                    n:'b'; 
        arr:['4','5','6'] 
      }]; 
    }) 

[b]html 代码:[/b]
<BR>    
<div ng-controller="indexCtrl"><BR>      
<p>{{name}}</p><BR>      

<ul><BR>        
 <li ng-repeat="name in names">{{name.n}}<BR>          
 <p ng-repeat="a in name.arr track by $index" id="{{$index}}">{{a}}</p><BR>        
 </li><BR>      
</ul>
<BR>    
</div><BR><BR> 

track by $index  在有重复值时需加上这段代码 不然浏览器会报这个错 Error: [ngRepeat:dupes]并且不会渲染到页面 以上这篇angular ng-repeat数组中的数组实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部