2016-10-10 20 views
0

我有這種情況,我ng-repeat我可以得到工作到一定的水平,但任何更深我找不到數組。ng-repeat在certin深度不工作,angularjs

這裏是我的代碼,同時也低於plunkr:

<div ng-repeat="row in data"> 
    <label ng-repeat="key in keys"> 
     {{row[key]}} 
     <input name="optradio" type="radio"/> 
    </label> 


這PLunker工程確定,但我想,深入到選項層只顯示選項1和選項。

http://plnkr.co/edit/xNVVFohA6DeU9nCgi7fQ?p=preview

任何幫助感激地接受。

感謝

回答

0

options是一個數組所以你只需要遍歷它

var app = angular.module('app', ['ui.bootstrap']); 
 
app.controller('Ctrl', ['$scope', 
 
    function($scope) { 
 

 
    $scope.data = [{ 
 
     "property": "http://api.mydomain.co.uk/", 
 
     "type": "Selection", 
 
     "options": [{ 
 
     "text": "Option 01", 
 
     "value": "http://api.mydomain.co.uk/O", 
 
     "type": "SelectionOption" 
 
     }, { 
 
     "text": "Option 02", 
 
     "value": "http://api.mydomain.co.uk/L", 
 
     "type": "SelectionOption" 
 
     }] 
 
    }]; 
 

 
    $scope.keys = Object.keys($scope.data[0]); 
 
    } 
 
]);
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <link data-require="[email protected]" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /> 
 
    <script data-require="[email protected]*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script> 
 
    <script data-require="[email protected]*" data-semver="0.10.0" src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.10.0.js"></script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script src="script.js"></script> 
 
</head> 
 

 
<body ng-app="app" ng-controller="Ctrl"> 
 

 
    <div ng-repeat="row in data"> 
 
    <label ng-repeat="opt in row.options"> 
 
     {{opt.text}} 
 
     <input name="optradio" type="radio" /> 
 
    </label> 
 
    <br> 
 
    </div> 
 

 
</body> 
 

 
</html>

+0

啊很容易,當你知道怎麼辦。非常感謝。 – wwwredback

+0

@wwwredback沒問題的隊友!如果它對你有幫助,不要忘了標記它作爲答案 – Weedoze