我正在尝试使用嵌套的ng-repeat。但是,上部 ng 中的值重复将作为内部 ng 重复中的参数传递。我正在尝试创建一个函数返回一个数组,以便我可以在内部 ng-repeat 中使用它。但它似乎不起作用。我怎样才能做到这一点?这是我的网页
<table class="table table-condensed" id="paytable" ng-repeat="row in employeeInfo">
<thead>
<tr>
<td class="col-sm-3">Employee Info</td>
</tr>
</thead>
<tbody>
<tr>
<td>{{employeeInfo.name}}</td>
<td>
<ul ng-repeat="row in employeeLoans(employeeInfo)">
<li></li>
</ul>
</td>
</tr>
</tbody>
</table>
这是角度
// this
$http.get('/api/PreviewEmployee').success(function (data)
{
$scope.employee = data;
$scope.Allowances = Allowance(data);
});
$scope.Allowance = function (data)
{
var result = [];
for(var i = 0 ; i < data.length ; i++)
{
result.push(data[i]);
}
console.log(result)
return result;
}
提前谢谢!!
我用示例数据创建了代码笔var x = $scope.employee;
var keys = Object.keys($scope.employee);
var result = [];
for (var i = 0; i < keys.length; i++) {
result.push(x[keys[i]]);
}
$scope.Allowances = result;
console.log($scope.Allowances);});
代码笔网址 -http://codepen.io/nagasai/pen/EyPZjQ 供参考
希望这对您有帮助:)