将字符串值从控制器获取到Visual force组件

时间:2016-03-16 07:20:49

标签: javascript salesforce apex

我想使用JavaScript从组件中的控制器获取值,但我是新手,所以我不知道如何实现它。这是我的控制器类:

public with sharing class DragAndDropMultipleDirect
{
    Public string orgID {get;set;}
    Public string userID {get;set;}
    Public string s3path {get;set;}
    public DragAndDropMultipleDirect()
    {

    }

    public String path()
    {
        String orgID = UserInfo.getOrganizationId() ;
        String userID =UserInfo.getUserId();
        String s3path ='string/'+orgID+'/'+userID;
        system.debug('orgID ==== ???  '+s3path);
        return s3path;
    }

我想在组件的脚本中使用s3path的值。

<apex:component Controller="DragAndDropMultipleDirect">
    <apex:attribute name="parentId" type="String" description="Parent record"/>
    <Script>
        function readfiles(files) {
            var path = **Here I want the value of s3Path**
            ----- code----
        }
    </Script>
</apex:component>

1 个答案:

答案 0 :(得分:0)

问题是s3Path应该保存该值。这是修改后的控制器和组件:

public class DragAndDropMultipleDirect
{
    public string orgID {get;set;}
    public string userID {get;set;}
    public string s3path {get;set;}

    public DragAndDropMultipleDirect()
    {
        s3path = 'string/' + UserInfo.getOrganizationId() + '/' + UserInfo.getUserId();
    }
}

Visualforce组件:

<apex:component Controller="DragAndDropMultipleDirect">
    <apex:attribute name="parentId" type="String" description="Parent record"/>

    <Script>
        function readfiles(files) {
            var path = '**Here I want the value of {!s3path}**';
        }
    </Script>
</apex:component>