1

我正在尝试使用 Coldfusion (cfquery) 创建一个查询来检索几个美元金额,添加它们,然后查看它是否与应用程序中计算的美元金额相匹配。但是,它什么也没做。

我正在尝试在 javascript 中完成所有这些工作。

这是代码。

function ValidateFunding(){
   var casenum = document.getElementById('CaseNum').value;
   var cycle = document.getElementById('Cycle').value;
   var year = document.getElementById('FSYear').value;
   var cnty = document.getElementById('selCounty'); 
   var cntyID = cnty.options[cnty.selectedIndex].value;

   <cfquery name="PSP" datasource="QueryTest">
    SELECT g.Fee220 + g.Fee330 + g.Fee456 + g.Fee225 AS GrandTotal
      FROM ProgFees g INNER JOIN County ON g.CountyID = cntyID
     WHERE g.Year = year
       AND g.Cycle = cycle
       AND g.CaseNum = casenum       
   </cfquery>
   if (document.getElementById('totbud').value = PSP.GrandTotal){
    alert('The fee matches.');
    return false;
   }
   else 
  {
    alert('Fees do not match.');
  }
         return true;
} 
4

1 回答 1

0

这是我为测试准备的页面。代码中有注释可以帮助解释发生了什么。两个关键行是<cfajaxproxy>标签,jd.getData();是我对 CF 的 AJAX 调用。

<cfscript>
variables.folders = {"client":["Favorites","Not Used"],"org":["2012","2011"],"public":["New","Old"]};
</cfscript>    
<cfajaxproxy cfc="cfc.jsondata" jsclassname="emaildata" /> 
<!DOCTYPE html>
<html>
    <head>
    <title>DevJSON</title>
    <script src="js/jquery.1.7.2.js" type="text/javascript" language="JavaScript"></script>
    <script src="js/handlebars.js" type="text/javascript" language="JavaScript"></script>
    <link rel="stylesheet" href="css/json.css" type="text/css"/>
    <script type="text/javascript">
        <!--- toScript will output CF vars as js vars --->
    <cfoutput> 
        var #toScript(variables.folders, 'folders')#;
        var #toScript(cgi.http_host & '/data/emaildata.json','jsonPath')#;
    </cfoutput> 
        var jd = new emaildata();
        // setup my js object from cfajaxproxy above

        var buildGrid = function(dataObj){
            var menus;
            var source = $('#grid').html();
            var template = Handlebars.compile(source);
            $("#mainContent").hide(); 
            $("#mainContent").children().remove();
            $("#mainContent").append(template(dataObj));
            $("#mainContent").fadeIn('slow');
        }

        // Error handler for the asynchronous functions. 
        var badJson = function(statusCode, statusMsg){ 
            alert('Status: ' + statusCode + '<br /><br /> ' + statusMsg); 
        }

        // output data 
        var buildmenu = function(){
            $.each(folders, function(fkey,fval) {
                if(this.indexOf() < 1){
                    $('li[data-type="' + fkey + '"] > div').append('<ul class="' + fkey + '"></ul>');
                }
                $.each(fval, function(dkey, dval){
                    $('[class="' + fkey + '"]').append('<li id="' + fkey + '">' + dval + '</li>');
                });
            });
        }            

        $(document).ready(function(){
            buildmenu();
            $('.directory > ul > li').click( function() {
                //set callback, errorhandler and then call the getData function in my CFC
                jd.setCallbackHandler(buildGrid);
                jd.setErrorHandler(badJson);
                jd.getData(this.id);
                $(".directory > ul > li").removeClass("highlight");
                $(this).addClass('highlight');                    
        });
            $("#mainContent").css('display','none');    
            $('li[data-type]').css('cursor','pointer');

        });

    </script>
    <!--- Setup handlebars template --->
    <script id="grid" type="text/x-handlebars-template">
        <div class="gridDetail">
            {{#each DATA}}
                <div class="row">
                    {{#each this}}
                    <span class="cell">
                      {{.}}&nbsp;
                    </span>
                    {{/each}}
                </div>
            {{/each}}
        </div>
    </script>            
</head>
于 2013-03-13T19:26:44.133 回答