对嵌套在数组中的数组使用ng-repeat

时间:2017-03-21 23:44:27

标签: html angularjs json

我有一个json文件,我可以使用

$scope.load = function() {
        var httpRequest = $http.get('json/properties.json')
            .then(function(res) {
                $scope.properties = res.data;
            });
    };

Json文件类似于:

        [{
        "property": "address",
        "options": ["zipCode", "city", "cityPrefix", "citySuffix", "streetName", "streetAddress", "streetSuffix", "streetPrefix", "secondaryAddress", "county", "country", "countryCode", "state", "stateAbbr", "latitude", "longitude"]
    }, {
        "property": "commerce",
        "options": ["color", "department", "productName", "price", "productAdjective", "productMaterial", "product"]
    }, {
        "property": "company",
        "options": ["suffixes", "companyName", "companySuffix", "catchPhrase", "bs", "catchPhraseAdjective", "catchPhraseDescriptor", "catchPhraseNoun", "bsAdjective", "bsBuzz", "bsNoun"]
    }]

我有这个HTML:

<div ng-repeat="(property, options) in properties ">
  <p>{{property}} - {{options}}</p>
</div>

对于我的JSON数组中的每个条目,我想创建一个包含&#34;属性&#34;的列表。值和此列表中的每个&#34;选项&#34;这个属性,但由于某种原因,我最接近的是每个属性有15(?)列表。 有帮助吗?
[编辑]
Link to current github repository

2 个答案:

答案 0 :(得分:2)

AngularJS ng-repeat duplicate error docs开始:

<div ng-repeat="(property, options) in properties track by $index">
   <p>{{property}} - {{options}}</p>
</div>

答案 1 :(得分:0)

我认为使用跟踪$ index会有效。

&#13;
&#13;
<div ng-repeat="(property, options) in properties track by $index">
          <p>{{property}} - </p>
          <ul>
             <li ng-repeat="option in options track by $index">{{option}}</li>
          </ul>
        </div>
&#13;
&#13;
&#13;