我在force.com apex 模板的pageBlockSection 内有一个表格。在我尝试在其中一个单元格内使用 outputText 标签之前,这种方法工作得很好。当我使用此标签时,额外的单元格和行会添加到标记中。但是,如果我不将表格嵌套在 pageBlockSection 标记内,则不会添加此类单元格。
我是否错误地使用了outputText,或者force.com上是否存在错误?
以下是重现此问题的最小标记:
<apex:pageBlock title="My Page Block">
<apex:pageBlockSection title="My Section">
<table>
<tr><th>1</th><th>2</th></tr>
<tr>
<td>
<apex:outputText value="{0}">
<apex:param value="one" />
</apex:outputText>
</td>
<td>
<apex:outputText value="{0}">
<apex:param value="two" />
</apex:outputText>
</td>
</tr>
</table>
</apex:pageBlockSection>
</apex:pageBlock>
这是由force.com呈现的输出:
<table>
<tbody>
<tr><th>1</th><th>2</th></tr>
<tr>
<td></td>
<td colspan="2" class="dataCol first ">one</td>
</tr>
<tr>
<td colspan="2" class="dataCol "></td>
<td></td>
<td colspan="2" class="dataCol ">two</td>
</tr>
<tr>
<td colspan="2" class="dataCol last "></td>
</tr>
</tbody>
</table>
最佳答案
我不能说这是否真的是一个错误,但我相信它是由 <apex:pageBlockSection>
引起的因为它们会自动将嵌套内容添加到表格中,从而与您自己的表格发生冲突。
我建议删除 <apex:pageBlockSection>
并将您的表直接放入 <apex:pageBlock>
,或删除您自己的表并利用 <apex:pageBlockSectionItem>
元素代替:
<apex:pageBlock title="My Page Block">
<apex:pageBlockSection title="My Section">
<apex:pageBlockSectionItem >
1
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
2
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputText value="{0}">
<apex:param value="one" />
</apex:outputText>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputText value="{0}">
<apex:param value="two" />
</apex:outputText>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
关于salesforce - VisualForce 中的嵌套表问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10806950/