角度显示JSON数组中的数据

时间:2014-07-23 13:56:48

标签: json angularjs

我似乎无法弄清楚我在这里做错了什么。我想深入查看下面的JSON数组,以显示月份数组中的数据。

我的架构:

var mongoose  = require('mongoose');
var Schema    = mongoose.Schema;

var CalendarSchema   = new Schema({

August: [
  {
    day: String,
    title: String,
    summary: String,
    description: String
  }
      ]
});

var Calendar = mongoose.model('CalendarData', CalendarSchema);



Calendar.find({}).exec(function(err, collection){
  if(collection.length === 0){
  Calendar.create({
'August': [
    {
      'day':'21', 
      'title':'cal title', 
      'summary': 'calsummary', 
      'decription': 'cal desc'
    }
          ]
    });
  }
});


module.exports = mongoose.model('CalendarData',  CalendarSchema);

我的角度控制器

 $scope.calendar = [];

 CAL.API.query(function(results) {
        $scope.calendar = results;
    }); 

我的观点

<div class="events" ng-repeat="cal in calendar.August">
   <h5>{{cal.title}}</h5>
</div>

JSON对象进入控制器

[
  -{
    _id: "53cfb6616ba190954d7682aa"
    __v: 0
    -August: [
         -{
          day: "21"
          title: "cal title"
          summary: "calsummary"
          _id: "53cfb6616ba190954d7682ab"
          }
            ]
    }
]

1 个答案:

答案 0 :(得分:2)

August是一个数组内部的数组你应该在ng-repeat ...

中迭代它
<div class="events" ng-repeat="event in calendar[0].August">
   <h5>{{event.title}}</h5>
</div>