2016-03-16 33 views
0

我想要使用JavaScript的組件中的控制器的值,但我是新手,因此我不知道如何實現它。這是我的控制器類:從控制器獲取字符串值到Visual force組件

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> 

回答

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>