首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将HTML输入val传递给APEX控制器

将HTML输入val传递给APEX控制器
EN

Stack Overflow用户
提问于 2016-02-23 08:38:46
回答 1查看 1.5K关注 0票数 2

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

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

这是我现在所拥有的,减去这个问题不需要的代码。使用它,控制台输出始终为null...

页面代码:

代码语言:javascript
复制
<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>

组件代码:

代码语言:javascript
复制
<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>

控制器代码:

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

发布于 2016-02-24 04:48:34

我认为你的解决方法很简单:你正在使用jQuery,而$与内部的Salesforce函数冲突。您需要使用noConflict。执行以下操作:

代码语言:javascript
复制
var j$ = jQuery.noConflict();
// setting variables with data from the page
var codRequested = j$("#datepicker").datepicker("getDate");
var velocityRequested = j$("#velocity-input").val();
....

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35566689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档