某些条件下的ng-repeat

时间:2018-02-11 11:09:53

标签: angularjs json

我有一个JSON,其属性prizes在某些情况下是这样的:

"prize" : {
  "Firstyear" : {
    "first" : 3000,
    "second" : 2000,
    "total" : 5000
     },
  "Secondyear" : {
    "first" : 3000,
    "second" : 2000,
    "total" : 5000
     },
  "Thirdyear" : {
    "first" : 3000,
    "second" : 2000,
    "total" : 5000
     },
   "total" : 15000
  },

但在某些情况下,就像这样:

"prize" : {
    "first" : 4000,
    "second" : 3000,
    "third" : 2000,
    "total" : 9000
},

我如何ng-repeat超过这些?

1 个答案:

答案 0 :(得分:0)

除非您想获取对象的键和值,否则不能对Object执行ng-repeat。我想你需要以下内容。

<强>样本

import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController } from 'ionic-angular';
import  Highcharts from 'highcharts';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage{
 @ViewChild("container", { read: ElementRef }) container: ElementRef;
  constructor(public navCtrl: NavController) {

  }
  ionViewDidLoad() {
    Highcharts.chart(this.container.nativeElement, {
      chart: {
        type: 'bar'
      },
      title: {
        text: 'Fruit Consumption'
      },
      xAxis: {
        categories: ['Apples', 'Bananas', 'Oranges']
      },
      yAxis: {
        title: {
          text: 'Fruit eaten'
        }
      },
      series: [{
        name: 'Jane',
        data: [1, 0, 4]
      }, {
        name: 'John',
        data: [5, 7, 3]
      }]
    })
  }

}
var uniqcApp = angular.module('uniqueApp',[]);
uniqcApp.controller('testController', function ($scope){
   $scope.data = {"prize" : {
    "first" : 4000,
    "second" : 3000,
    "third" : 2000,
    "total" : 9000
}};
});