ajax - Visualforce在页面加载时通过Ajax加载apex组件

标签 ajax salesforce pageload apex-code visualforce

有人可以告诉我如何使用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/

相关文章:

html - 使用 CSS 在图像上绘制圆圈

html - html 5 上的元数据预加载属性是否加载整个视频?

javascript - 延迟 Javascript 或 div 直到页面加载

php - 多个复选框过滤器未正确过滤

java - 单击任何按钮时如何显示正在加载的 gif

javascript - 我无法使用 map 功能 TypeError : Cannot read property 'map' of undefined

salesforce - 顶点中 Http* 方法 : system. RestRequest 的无效类型

javascript - 使用 Ajax 将可变数据作为帖子发送

java - Rest API 调用拒绝 Cookie

c# - 为什么页面加载事件没有触发?