在这种情况下,我将使用一个类并拥有该类的对象列表:
class CTimeSlot
{
public Time tStart {get; set;}
public Appointment__c sAppointment {get; set;}
public CTimeSlot(Time startTime)
{
tStart = startTime;
Appointment__c = null;
}
}
// ** snip **
list<CTimeSlot> liTimeSlots = new list<CTimeSlot>();
// ** snip ** loop through times, and for each add an entry to the list
CTimeSlot newSlot = new CTimeSlot(loopTime);
liTimeSlots.add(newSlot);
mapTimeToSlot.put(loopTime + '', newSlot);
}
// ** snip ** when running through your query results of Appointment__c objects:
for(Appointment__c sAppointment : [select Id, Time__c from Appointment__c where ...])
{
if(mapTimeToSlot.get(sAppointment.Time__c) != null)
{
mapTimeToSlot.get(sAppointment.Time__c).sAppointment = sAppointment;
}
}
然后,您可以用 CTimeSlot 的实例填充此列表,并且对于您有约会的时间,将其设置为实例上的 sAppointment — 这也可以通过使用插槽映射来更容易,映射时间(作为字符串)到 CTimeSlot。
在页面中,您可以重复列表:
<table>
<apex:repeat var="slot" value="{!liTimeSlots}">
<tr>
<td><apex:outputText value="{!slot.tStart}"/></td>
<td>
<apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.SomeField)}"/>
</td>
</tr>
</apex:repeat>
希望这会给你一些想法,让你走上正确的道路!