AngularJS动态显示多条记录

AngularJS Dynamically displaying the multiple records

本文关键字:记录 动态显示 AngularJS      更新时间:2023-09-26

下面是我的AngularJS代码。我正在向roleList添加四条记录。但是我想将N个记录添加到roleList。我怎样才能做到这一点。

$scope.roleList = [
    {"companyName": "Company 01", "id":"1", "position": "CEO"},
    {"companyName": "Company 02", "id":"2", "position": "Board of Director"},
    {"companyName": "Company 01", "id":"1", "position": "CEO"},
    {"companyName": "Company 02", "id":"2", "position": "Board of Director"}
];

为什么不制作for

var limit=100;
var roleList=[];
for(var i=0;i<limit;i++){
   roleList.push({
     companyName:'some name', 
     id:i,
     position:'some position'
   });
}
$scope.roleList=roleList;