0

我在一个函数 (2) 中构建一个选择,然后在另一个函数 (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)

        }
    })
}

提前致谢

4

1 回答 1

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);
        }
    })

}

函数 deptApproverSelect(id,nameType,eid){ var deptid = #qGetMyDept.DIV_DEPARTMENTID#; $.ajax({type: "GET",url: "CFCs/approvers.cfc",dataType: "json",async: false,data: {method: "DEPAPPROVER_RLUz",deptid: deptid },success: function(response ){ var data = response.DATA; var selectApprover = ''; selectApprover += 'Select Approver'; 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{ 变量选择 = ''; } selectApprover += ''+显示+''; } selectApprover += ''; $('#'+nameType).html(selectApprover); } }) }

于 2013-08-21T17:05:38.227 回答