动态jQueryUI对话框回调函数问题

Dynamic jQuery UI dialog callback function problems

我在使用 jQuery UI 对话框模式时遇到问题,并尝试传入动态 name/value 以用作要执行的回调函数(以及参数)

我有一个调用 UI 对话框的函数....接受参数列表,其中之一是回调函数名称..以及伴随它的任何参数。

我无法 jQuery 识别动态 name/parms 被视为一个函数。

function ShowDialogBox(title, content, btn1text, btn2text, callbackFunction, argList){
var btn1css;
var btn2css;

//hide buttons if not in use
if(btn1text == ''){
    btn1css = "hidecss";
}else{
    btn1css = "showcss";
}

if(btn2text == ''){
    btn2css = "hidecss";
}else{
    btn2css = "showcss";
}

//main message/content
$("#lblMessage").html(content);


//params
$("#dialog").dialog({
    resizable: false,
    title: title,
    modal: true,
    width: '400px',
    height: 'auto',
    bgiframe: false,
    //hide: {effect: 'scale', duration: 100},
    
    buttons: [
        {
            text: btn1text,
            "class": btn1css,
            click: function () {
                //alert("button 1 pressed");
                
                //new dialog when cup is in position
                console.log('Call Back Check: ' + callbackFunction);
                console.log("Arg List: " + argList);
                eval(callbackFunction + '()'); // executes, but cant get any params?
                eval(callbackFunction + '(' +argList +')'); //doesnt work
                //callbackFunction(argList); // doesnt work


                //functionTest = window[callbackFunction];
                //functionTest(argList);
                
                //Goal: call new ShowDialogBox with different callback function name
                //ShowDialogBox('', 'Press start when the cup is in the holder.', 'Start', '', 'submitFunction',null);
                
                $("#dialog").dialog('close');
                
            }
        },
        {
            text: btn2text,
            "class": btn2css,
            click: function () {
                //alert("button 2 pressed");
                $("#dialog").dialog('close');
            }
        }
    ]
});

}

callbackFunction - 要调用的回调函数的名称(ShowDialogBox) argList - params/arguments 伴随所述回调函数

的列表

调用方式如下(回调函数名称再次为 ShowDialogBox [但这次回调函数不同])

ShowDialogBox('','Are you sure you want to order: <br>' + currentSelection, 'Continue','No', 'ShowDialogBox','mutiple ags go here, as commana string? array?');

我的问题:

1.) 如何传递:ShowDialogBox 作为回调函数 argument/value,并将其视为在单击按钮 #1 后执行的实际函数?

2.) 我怎样才能将参数列表传递给这个 'dynamically' 命名回调数组?

更新:所以我可以执行动态函数(可以这么说)..但我似乎无法传递任何参数?

更新 2:现在有人向我指出了传播语法..一切都在满足我的需要..但我想我有一个关于扩展它的问题?

有效:(因为我最后一个嵌套的回调函数没有任何要传递的参数)

//double verify (dialog prompts)
ShowDialogBox('','Are you sure you want to order: <br>' + currentSelection, 'Continue','No', ShowDialogBox, '', 'Please place drink in holder and press start when ready.', 'Start', '', submitForm, '');

虽然这不起作用..因为传递了一个额外的嵌套 callBackFunction 名称..和参数? (但是由于第一个 callBackFunction 参数之后的所有内容现在都是“...argList”。我不知道如何访问它?(如果可能的话))

ShowDialogBox('','Are you sure you want to order: <br>' + currentSelection, 'Continue','No', callBackTest, 'Some Title', 'Some Message', 'Button 1 text', 'Button 2 text', someOtherCallBackFunction, 'no', 'args allowed', 'in nested callback function? how is it done (again?)');

第一个问题,回调函数名不加引号即可

ShowDialogBox('', text , 'Continue','No', submitForm);

function submitForm() { /* ... */ }

要向其传递动态数量的参数,请使用 spread syntax,这将创建一个数组,其中包含传递给函数并返回到各个参数的所有剩余参数。

function ShowDialogBox(title, content, btn1text, btn2text, callbackFunction, ...argList) {
    // Execute the callback
    callbackFunction(...argList);
}