jquery函数没有将html返回给第二个函数

时间:2013-08-20 12:59:49

标签: jquery coldfusion cfc coldfusion-10

我在一个函数(2)中构建一个select,然后在另一个函数(1)中调用它,在那里我传递构建函数所需的值并选择合适的批准者。一切正常,除了将html传回函数(1)。

功能(1)

function loadTravelRules(id){

    $.ajax({type: "GET",url: "CFCs/myapprovers.cfc",dataType: "json",data: {method: "MYAPPROVERS_RLUz",MYAPPROVERSID: id
            },success: function(response){
                var rdata = response.DATA;
                var str = '<ul>';
                for (var i = 0; i < rdata.length; i++) {
                    var aid = response.DATA[i][response.COLUMNS.indexOf('MYAPPROVERSID')];
                    var auditor = response.DATA[i][response.COLUMNS.indexOf('DEPTAUDITAPPROVEREMPLID')];
                    var firstApprover = response.DATA[i][response.COLUMNS.indexOf('FIRSTAPPROVEREMPLID')];
                    var secondApprover = response.DATA[i][response.COLUMNS.indexOf('SECONDAPPROVEREMPLID')];
                    var thirdApprover = response.DATA[i][response.COLUMNS.indexOf('THIRDAPPROVEREMPLID')];
                    var firstDivApprover = response.DATA[i][response.COLUMNS.indexOf('FIRSTDIVAPPROVEREMPLID')];
                    var secondDivApprover = response.DATA[i][response.COLUMNS.indexOf('SECONDDIVAPPROVEREMPLID')];
                    var deptOverRide = response.DATA[i][response.COLUMNS.indexOf('DEPTOVERRIDEEMPLID')];
                    var title = response.DATA[i][response.COLUMNS.indexOf('APPROVALRULE')];

                    var auditorSelect = deptApproverSelect(id=aid,nameType="timekeeper",eid=auditor);

                str += '<li>Auditor: '+auditorSelect+'</li>';
                str += '<li>First Approver: '+firstApprover+'</li>';
                str += '<li>Second Approver: '+secondApprover+'</li>';
                str += '<li>Third Approver: '+thirdApprover+'</li>';
                str += '<li>First Div. Approver: '+firstDivApprover+'</li>';
                str += '<li>Second Div. Approver: '+secondDivApprover+'</li>';
                str += '<li>Dept. Override: '+deptOverRide+'</li>';
                }
             str += '</ul>';
             $('#manageApprovers').dialog({
                title: title+' Rules',
                modal:true
             }).html(str);
            }
        })
}

功能(2)

function deptApproverSelect(id,nameType,eid){
    var deptid = <cfoutput>#qGetMyDept.DIV_DEPARTMENTID#</cfoutput>;

    $.ajax({type: "GET",url: "CFCs/approvers.cfc",dataType: "json",async: false,data: {method: "DEPTAPPROVER_RLUz",deptid: deptid
        },success: function(response){
            var data = response.DATA;
            var selectApprover = '<select id="'+nameType+'_'+id+'" name="'+nameType+'">';
            selectApprover += '<option value="" selected="selected">Select Approver</option>';
                for (var i = 0; i < data.length; i++) {
                    var display = response.DATA[i][response.COLUMNS.indexOf('FULL_NAME')];
                    var emplid = response.DATA[i][response.COLUMNS.indexOf('EMPLID')];
                    if(emplid==eid){
                        var selected = 'selected="selected"';
                    }else{
                        var selected = '';
                    }
                    selectApprover += '<option value="'+emplid+'"'+selected+'>'+display+'</option>';
                }
                selectApprover += '</select>';
                console.log(selectApprover)

        }
    })
}

提前致谢

1 个答案:

答案 0 :(得分:0)

问题解决了:

function loadTravelRules(id){
$.ajax({type: "GET",url: "CFCs/myapprovers.cfc",dataType: "json",data: {method: "MYAPPROVERS_RLUz",MYAPPROVERSID: id
        },success: function(response){
            var rdata = response.DATA;
            var str = '<ul">';
            for (var i = 0; i < rdata.length; i++) {
                var aid = response.DATA[i][response.COLUMNS.indexOf('MYAPPROVERSID')];
                var auditor = response.DATA[i][response.COLUMNS.indexOf('DEPTAUDITAPPROVEREMPLID')];
                var firstApprover = response.DATA[i][response.COLUMNS.indexOf('FIRSTAPPROVEREMPLID')];
                var secondApprover = response.DATA[i][response.COLUMNS.indexOf('SECONDAPPROVEREMPLID')];
                var thirdApprover = response.DATA[i][response.COLUMNS.indexOf('THIRDAPPROVEREMPLID')];
                var firstDivApprover = response.DATA[i][response.COLUMNS.indexOf('FIRSTDIVAPPROVEREMPLID')];
                var secondDivApprover = response.DATA[i][response.COLUMNS.indexOf('SECONDDIVAPPROVEREMPLID')];
                var deptOverRide = response.DATA[i][response.COLUMNS.indexOf('DEPTOVERRIDEEMPLID')];
                var title = response.DATA[i][response.COLUMNS.indexOf('APPROVALRULE')];
            str += '<li>Auditor: <span id="auditor"></span></li>';
            str += '<li>First Approver: <span id="firstApprover"></span></li>';
            str += '<li>Second Approver: <span id="secondApprover"></span></li>';
            str += '<li>Third Approver: <span id="thirdApprover"></span></li>';
            str += '<li>First Div. Approver: <span id="firstDivApprover"></span></li>';
            str += '<li>Second Div. Approver: <span id="secondDivApprover"></span></li>';
            str += '<li>Dept. Override: <span id="deptOverRide""></span></li>';
            }
         str += '</ul>';
         $('#manageApprovers').dialog({
            title: title+' Rules',
            width:330,
            modal:true
         }).html(str);
            deptApproverSelect(id=aid,nameType="auditor",eid=auditor);
            deptApproverSelect(id=aid,nameType="firstApprover",eid=firstApprover);
            deptApproverSelect(id=aid,nameType="secondApprover",eid=secondApprover);
            deptApproverSelect(id=aid,nameType="thirdApprover",eid=thirdApprover);
            deptApproverSelect(id=aid,nameType="firstDivApprover",eid=firstDivApprover);
            deptApproverSelect(id=aid,nameType="secondDivApprover",eid=secondDivApprover);
            deptApproverSelect(id=aid,nameType="deptOverRide",eid=deptOverRide);
        }
    })

}

function deptApproverSelect(id,nameType,eid){     var deptid = #qGetMyDept.DIV_DEPARTMENTID#;     $ .ajax({type:&#34; GET&#34;,url:&#34; CFCs / approvers.cfc&#34;,dataType:&#34; json&#34;,async:false,data:{method :&#34; DEPTAPPROVER_RLUz&#34;,deptid:deptid         },success:function(response){             var data = response.DATA;             var selectApprover =&#39;&#39 ;;             selectApprover + =&#39;选择审批者&#39 ;;                 for(var i = 0; i&lt; data.length; i ++){                     var display = response.DATA [i] [response.COLUMNS.indexOf(&#39; FULL_NAME&#39;)];                     var emplid = response.DATA [i] [response.COLUMNS.indexOf(&#39; EMPLID&#39;)];                     如果(EMPLID == EID){                         var selected =&#39; selected =&#34; selected&#34;&#39 ;;                     }其他{                         var selected =&#39;&#39 ;;                     }                     selectApprover + =&#39;&#39; + display +&#39;&#39 ;;                 }                 selectApprover + =&#39;&#39 ;;                 $(&#39;#&#39 + NAMETYPE)的.html(selectApprover);         }     }) }