我正在使用visualforce页面。我在页面中使用datatable,我在每一行都使用了一个复选框,现在我只想获得复选框值为true的那些行,代码如下所示。
<apex:page controller="searchDuplicate">
<apex:pageBlock title="Searching for Duplicate Contacts Record">
<center>
<apex:form>
<apex:dataTable id="dTable" value="{!selectedContactList}" var="cn" border="1" cellpadding="5">
<apex:column headerValue="Name" value="{!cn.Name}" />
<apex:column headerValue="Email" value="{!cn.Email}" />
<apex:column headerValue="Select">
<apex:inputCheckbox/>
</apex:column>
</apex:dataTable>
<apex:commandButton value= "Delete Selected"/>
</apex:form>
</center>
</apex:pageBlock>
</apex:page>
答案 0 :(得分:0)
出于多种原因,我不会使用JavaScript。首先,Visualforce处理会在列表tricky中跟踪组件ID。当列表包含标准或自定义SObject时,处理此问题的最佳方法是在Apex中使用wrapper class。然后您可以像这样访问您的值(其中c是包装的联系人):
<apex:column headerValue="Name" value="{!cn.c.Name}" />
<apex:column headerValue="Email" value="{!cn.c.Email}" />
<apex:inputCheckbox value="{!cn.theBoolean}"/>
请注意,cn.theBoolean不是cn.c.theBoolean。那是因为您的联系人记录现在包含在自定义Apex类中,如下所示:
public List<ContactWrapper> selectedContactList {get; set;}
// Inner-class
public class ContactWrapper
{
public Contact c {get; set;}
public Boolean theBoolean {get; set;}
public ContactWrapper(Contact c)
{
this.c = c;
}
...
希望有所帮助。