我想制定一个时间表。我从我的API接收对象为:AngularJS指令 -
schedule : {
id,
name,
shifts : []
}
// each shift is
shift : {
id,
schedule_id,
user,
tasks: []
}
// each task is
task: {
id,
shift_id,
time_start,
time_end
}
我的HTML目前(请参见下面的图像的什么样子,现在快照)
<div class="schedule">
<!-- This is the time of the day column, such as 10:00, 11:00 -->
<div id="clock"></div>
<div class="shifts">
<div class="shift" ng-repeat="shift in schedule.shifts">
<!-- The user assigned to this shift -->
<div class="user" ng-bind="shift.user"></div>
<!-- This is the time cells in 15min interval -->
<div class="cells">
<!-- Not going into detail, but this creates the cells
<div class="cell" ng-repeat="cell in cells"></div>
</div>
<!-- The tasks -->
<div class="tasks">
<div class="task" ng-repeat="task in shift.tasks"></div>
</div>
</div>
</div>
</div>
眼下,因为tasks
被放置在他们自己的容器中,然后将任务降到正确的开始时间,我基本上计算了task.time_start
与当天的开始时间有多不相同,然后将其转换为一个top: $some-pixel
的CSS(通过乘以时间差乘以每个小区的高度)。
我想立即将这些任务绑定到单元格上。但我该怎么做? tasks
位于shift.tasks
内部的数组中,我无法弄清楚在创建单元时如何循环它们。
或者我正在做的是对的?
编辑
,我能想到的是具有细胞内ng-repeat
为好,用ng-if
<div class="cells">
<div class="cell" ng-repeat="cell in cells">
<div class="task" ng-repeat="task in shift.task" ng-if="task.time_start = cell.time_start"></div>
</div>
</div>
Somehwat取决于所需的功能。例如,如果拖放需要。我发现,使用fullcalendar布置事件的方式更容易,将它们放在时间块之上的层上。然后只处理多个时间段的一个元素与一个任务的多个元素 – charlietfl
那么你可以通过给它一个保证金顶部或其他东西来调整开始时间然后右?像我现在正在做的方式 – Kousha
或使用绝对位置......正确。检查** [fullcalendar](http://arshaw.com/fullcalendar/)**中的dom,可能有所帮助。如果你的事件没有水平跨越列将使它比任何持续时间的日历更容易 – charlietfl