简体   繁体   中英

Angular displaying data from within JSON array

I can't seem to figure out what I'm doing wrong here. I'd like to drill down into the JSON array below to display data from within the months array.

My schema:

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);

my angular controller

 $scope.calendar = [];

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

My view

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

JSON object coming through to controller

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

August is an array inside of an array You should iterate over it in ng-repeat ...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM