ng-repeat: access key and value for each object in array of objects

前端 未结 6 778
清歌不尽
清歌不尽 2020-12-04 15:06

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 =         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 15:59

    I think the problem is with the way you designed your data. To me in terms of semantics, it just doesn't make sense. What exactly is steps for?

    Does it store the information of one company?

    If that's the case steps should be an object (see KayakDave's answer) and each "step" should be an object property.

    Does it store the information of multiple companies?

    If that's the case, steps should be an array of objects.

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

    In either case you can easily iterate through the data with one (two for 2nd case) ng-repeats.

提交回复
热议问题