Angular ng-repeat with nested json objects?

后端 未结 5 2069
鱼传尺愫
鱼传尺愫 2020-12-30 09:49

I have a JSON object, represented as such:

 {
  \"orders\" : [
    {
      \"ordernum\" : \"PRAAA000000177800601\",
      \"buyer\" : \"Donna Heywood\"
              


        
5条回答
  •  暖寄归人
    2020-12-30 10:49

    Actually its same answer of @sylwester. The better way to put it in filter. And you can reuse it by passing propertyName parameter.

    In your case we passed parcels

    JS

    myApp.filter('createarray', function () {
        return function (value, propertyName) {
            var arrayList = [];
            angular.forEach(value, function (val) {
                angular.forEach(val[propertyName], function (v) {
                    arrayList.push(v)
                });
            });
            return arrayList;
        }
    });
    

    HTML

    • {{o.upid}}

    Here is working Fiddle

提交回复
热议问题