我有一个visualforce组件,其中写有一些脚本,我直接想将一些值传递给controller.this是我的javascript代码。
<script>
function uploadComplete(evt) {
var city = 'Shimla';
var location = 'kkllkk'
**i want to pass city and location in IWantToDebug method**
function IWantToDebug() {
MyController.IWantToDebug(city,location, function(result, event) {
// Set the inputField value to the result in here
});
} </script>
我的apex控制器类方法就像。
public void IWantToDebug(String city , String location) {
System.debug('======================= ' + data);
}
答案 0 :(得分:0)
您可以使用actionfunction将值传递给控制器
将以下内容添加到组件的html部分:
<apex:actionFunction action="{!IWantToDebug}" name="IWantToDebugJavascriptSide" rerender="someComponentIdToRender">
<apex:param name="city " value=""/>
<apex:param name="location" value=""/>
</apex:actionFunction>
将您的javascript更改为
<script>
function uploadComplete(evt) {
var city = 'Shimla';
var location = 'kkllkk'
**i want to pass city and location in IWantToDebug method**
function IWantToDebug() {
IWantToDebugJavascriptSide(city,location);
});
</script>
将控制器更改为
public PageReference IWantToDebug() {
String city , String location;
if (Apexpages.currentPage().getParameters().containsKey('city')){
city = Apexpages.currentPage().getParameters().get('city'));
}
if (Apexpages.currentPage().getParameters().containsKey('location')){
location= Apexpages.currentPage().getParameters().get('location'));
}
System.debug('======================= ' + city + ' ' +location);
return null;
}
有关如何使用动作功能的更多参考,请访问 https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionFunction.htm
谢谢