2014-07-23 50 views
0

我正在构造一个角度的日历。构建JSON的最佳方法是什么才能使用边栏的月份并按月显示所显示的事件?角度使用JSON构造

是否有更灵活的方式来设置架构比我目前有?现在我必须为每个月定义一个新的模式。这里是一个链接到结束我正在使用http://secret-hollows-7338.herokuapp.com/events网页视图。

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

var CalendarSchema = new Schema({ 

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

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

我控制器

$scope.calendar = []; 

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

我看来

<div class="events" ng-repeat="cal in calendar[0].August"> 
    <a href="/events/{{cal.day}}"> 
    <article class="eventslist"> 
    <div class="numberedDate"> 
    <h3>{{cal.day}}</h3> 
    </div> 
    <div class="calInfo"> 
    <h5>{{cal.title}}</h5> 
    <p>{{cal.summary}}&nbsp;<a>more</p> 
    </div> 
    </article> 
    </a> 
</div> 

回答

0

可能有几种方法可以解决这个。

我看到它是只创建一个事件模型的方式:

var EventSchema = new Schema({ 
    date: { type: Date, default: Date.now }, 
    title: String, 
    summary: String, 
    description: String 
}); 

这样你存储日/月/年/小时的数据直接进入您的活动,你有排序更大的灵活性,过滤和各种用法。