有人可以告诉我如何使用ajax在页面加载时通过ajax加载apex pageBlockTable吗?我已经看到了显示如何使用顶点actionFunction的示例,但是示例通常很简单(例如-从 Controller 返回一个字符串并将其放在页面上。我的 Controller 返回了sObjects列表,但我不确定怎么做的。
页:
<apex:pageBlockTable value="{!TopContent}" var="item">
<apex:column headerValue="Title">
<apex:outputLink value="/sfc/#version?selectedDocumentId={!item.Id}">
{!item.Title}
</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
Controller :
List<ContentDocument> topContent;
public List<ContentDocument> getTopContent()
{
if (topContent == null)
{
topContent = [select Id,Title from ContentDocument limit 10];
}
return topContent;
}
最佳答案
我想通了。诀窍是使用actionFunction,然后直接从javascript调用它。
因此,VF页面如下所示:
<apex:page controller="VfTestController">
<apex:form>
<apex:actionFunction action="{!loadDocuments}" name="loadDocuments" rerender="pageBlock" status="myStatus" />
</apex:form>
<apex:pageBlock id="pageBlock">
<apex:pageBlockTable value="{!TopContent}" rendered="{!!ISBLANK(TopContent)}" var="item">
<apex:column headerValue="Title">
<apex:outputLink value="/sfc/#version?selectedDocumentId={!item.Id}">
{!item.Title}
</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
<apex:actionStatus startText="Loading content..." id="myStatus" />
</apex:pageBlock>
<script type="text/javascript">
window.setTimeout(loadDocuments, 100);
</script>
</apex:page>
和这样的 Controller :
public class VfTestController
{
List<ContentDocument> topContent;
public List<ContentDocument> getTopContent()
{
return topContent;
}
public PageReference loadDocuments()
{
if (topContent == null)
{
topContent = [select Id,Title from ContentDocument limit 10];
}
return null;
}
}
关于ajax - Visualforce在页面加载时通过Ajax加载apex组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3877426/