gpt4 book ai didi

jquery - 将 HTML 输入值传递给 APEX Controller

转载 作者:行者123 更新时间:2023-11-28 02:58:48 25 4
gpt4 key购买 nike

几天来我一直在研究和尝试各种代码,一直无法找到可靠的解决方案,所以我来找你们,希望你们能指出我做错了什么。

在我的自定义 VF 页面上,我使用了 4 个 HTML 输入标签,当用户单击生成按钮时,我希望将输入值传递到 Apex Controller 中进行操作。

这是我现在所拥有的,减去这个问题不需要的代码。有了它,控制台输出总是空的...

页面代码:

<apex:page id="scheduler-page" standardController="Opportunity" extensions="DEMO_ScheduleOpportunityController" showHeader="false" sidebar="false" standardStylesheets="false">

<head>
<script type="text/javascript">
function Generate() {
// setting variables with data from the page
var codRequested = $("#datepicker").datepicker("getDate");
var velocityRequested = $("#velocity-input").val();
var mwdcRequested = $("#mwdc-input").val();
var seriesRequested = $("#seriesList").val();
// these 4 values displays properly in the JS console
console.log('codRequested: ' + codRequested);
console.log('velocityRequested: ' + velocityRequested);
console.log('mwdcRequested: ' + mwdcRequested);
console.log('seriesRequested: ' + seriesRequested);
// passing values to the actionscript
SetInitialVariables(codRequested, velocityRequested, mwdcRequested, seriesRequested);
}
</script>
</head>

<body>
<apex:form id="scheduler-form">

<apex:actionFunction name="SetInitialVariables" action="{!GenerateSchedule}">
<apex:param name="codRequested" value="" />
<apex:param name="velocityRequested" value="" />
<apex:param name="mwdcRequested" value="" />
<apex:param name="seriesRequested" value="" />
</apex:actionFunction>

<c:DEMOscheduleGeneration opportunity="{!opportunity}" seriesMap="{!seriesMap}" />
</apex:form>

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js" />
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js" />
</body>

组件代码:

<apex:component>
<div id="generateContainer" class="container">
<!-- generate button -->
<div id="generate-button-wrap">
<a id="generate" onclick="Generate()">Generate</a>
<!-- calls JQ Generate function -->
</div>
</div>
</apex:component>

Controller 代码:

public PageReference GenerateSchedule() {        
String series = Apexpages.currentPage().getParameters().get('seriesRequested');
String mwdc = Apexpages.currentPage().getParameters().get('mwdcRequested');
String velocity = Apexpages.currentPage().getParameters().get('velocityRequested');
String cod = Apexpages.currentPage().getParameters().get('codRequested');
System.debug('Series: ' + series);
System.debug('MWdc: ' + mwdc);
System.debug('Velocity: ' + velocity);
System.debug('COD: ' + cod);
return null;
}

最佳答案

我认为您的修复非常简单:您正在使用 jQuery 并且 $ 与内部 Salesforce 函数冲突。您需要使用 noConflict。这样做:

var j$ = jQuery.noConflict();
// setting variables with data from the page
var codRequested = j$("#datepicker").datepicker("getDate");
var velocityRequested = j$("#velocity-input").val();
....

无论你在哪里使用$,都使用j$。这应该可以解决您的问题。

关于jquery - 将 HTML 输入值传递给 APEX Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35566689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com