Salesforce 基于选择列表上的选择显示字段
我有一个VF页面,其中我使用apex:pageblocktable来显示一组记录。 其中一列是选择列表,我需要根据选择列表上的选项显示/不显示字段Salesforce 基于选择列表上的选择显示字段,salesforce,apex-code,visualforce,Salesforce,Apex Code,Visualforce,我有一个VF页面,其中我使用apex:pageblocktable来显示一组记录。 其中一列是选择列表,我需要根据选择列表上的选项显示/不显示字段 <apex:pageBlockTable value="{!showRecord}" var="item"> <apex:column headerValue="Delivery"> <apex:inputField value="{!item.delivery__c}"/> </apex:
<apex:pageBlockTable value="{!showRecord}" var="item">
<apex:column headerValue="Delivery">
<apex:inputField value="{!item.delivery__c}"/>
</apex:column>
<apex:column headerValue="Roadway">
<apex:inputField value="{!item.road__c}"/>
</apex:column>
<apex:column headerValue="Rail">
<apex:inputField value="{!item.rail__c}"/>
</apex:column>
</apex:pageBlockTable>
在上面的代码交付中,c是带有值roadways和Rails的picklist。如果用户选择roadways,那么我需要显示road--c;如果用户选择Rails,那么我需要显示rail_c
我该怎么做呢
谢谢一种方法是在Visualforce中使用部分页面刷新 将两个字段放在同一列中,并使用“rendered”属性使用if语句动态显示/隐藏字段。然后,使用actionSupport标记为delivery_u_;c字段设置AJAX onchange事件处理程序。这将基本上侦听该字段的更改,然后刷新页面上的表。每次刷新时,if语句都将重新计算,结果显示该列中的两个字段之一 我没有机会尝试这个,但我认为它应该有效
<apex:pageBlockTable id="mytable" value="{!showRecord}" var="item">
<apex:column headerValue="Delivery">
<apex:actionRegion>
<apex:inputField value="{!item.delivery__c}">
<apex:actionSupport event="onchange" reRender="mytable">
</apex:inputField>
</apex:actionRegion>
</apex:column>
<apex:column headerValue="Delivery Type">
<apex:inputField rendered="{!item.delivery__c='Road'}" value="{!item.road__c}"/>
<apex:inputField rendered="{!item.delivery__c='Rail'}" value="{!item.rail__c}"/>
</apex:column>
</apex:pageBlockTable>