在Component-Visualforce中从javascript调用一个控制器方法


<apex:component>
 <apex:attribute name="l" description="l" type="double" assignTo="{!Received_L}"/>
  <apex:attribute name="varLng" description="t" type="double" assignTo="{!Received_T}"/>  
   //***** from here i want to call assignLocation()--------
</apex:component>

My Controller for Component

public class myController {
     public double Recieved_L{get;set;}
     public double Recieved_T{get;set;}
     public myController(){} //constructor        
    public PageReference assignLocation() {
        l=Recieved_L;
        t=Recieved_T;
        return null;
    }

我不想在构造函数中调用这个方法,我想在页面加载后调用myMethod()

从javascript调用Apex控制器方法的最好方法是使用
https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm

<apex:component>
 <apex:attribute name="l" description="l" type="double" assignTo="{!Received_L}"/>
  <apex:attribute name="varLng" description="t" type="double" assignTo="{!Received_T}"/>  
   //***** from here i want to call assignLocation()--------
  <apex:actionFunction name='myMethod' action='{!assignLocation}' />
</apex:component>

你需要一个javascript代码来调用这个动作函数,无论是从你的组件还是从组件外部的visualforce页面。关于如何实现这一目标的更多深入信息,请查看链接

最新更新