NG-重复:访问键和值对每个对象中的对象数组 [英] ng-repeat: access key and value for each object in array of objects

查看:150
本文介绍了NG-重复:访问键和值对每个对象中的对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有对象的数组和我使用的是 NG-重复来迭代他们,这是很容易。该阵列看起来是这样的:

I have an array of objects and I am using an ng-repeat to iterate over them, which is easy. The array looks something like this:

$scope.steps = [
    {companyName: true},
    {businessType: true},
    {physicalAddress: true}
];

和我的 NG-重复属性如下:

<div ng-repeat="step in steps"> ... </div>

在每次迭代中,步骤等于对象之一,如预期。反正是有访问这两个键和对象的值?这样我就可以做这样的事情:

In each iteration, step is equal to one of the objects, as expected. Is there anyway to access both the key and the value of the step object? So that I could do something like this:

<div ng-repeat="(stepName, isComplete) in steps"> ... </div>

其中, stepName == '的companyName isComplete == 真正。我试着这样做确切的事情,但 stepName 始终只是最终被步骤对象的索引(这是有道理的)。我只是想弄清楚是否有另一种方式写在 NG-重复语法,这样我可以得到键和值。

Where stepName == 'companyName' and isComplete == true. I've tried doing this exact thing but stepName always just ends up being the index of the step object (which makes sense). I'm just trying to figure out if there is another way to write the ng-repeat syntax so that I can get the key and the value.

感谢您的任何意见/建议。大部分AP preciated。

Thanks for any ideas/suggestions. Much appreciated.

PS。我目前的解决办法是刚做这在我的控制器:

PS. My current work around is to just do this in my controller:

$scope.stepNames = [];
angular.forEach($scope.steps, function(isComplete, stepName){
     $scope.stepNames.push({stepName: stepName, isComplete: isComplete});
});

然后遍历这一点,但它会很高兴做这一切在视图

And then to iterate over that, but it would be nice to do it all in the view

推荐答案

中继器内部的转发

<div ng-repeat="step in steps">
    <div ng-repeat="(key, value) in step">
        {{key}} : {{value}}
    </div>
</div>

这篇关于NG-重复:访问键和值对每个对象中的对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆