문제

jQuery UI 대화 상자 내부의 버튼에 대한 번역 된 레이블을 보유하는 변수가 있습니다.

버튼 배열 키를 변수 자체로 채울 수 없으며 내 변수를 문자열로 취급 할 수있는 방법을 찾을 수 없습니다.

translations['ok'] = 'ok';
translatinos['cancel'] = 'cancel';

// not working
jQuery('#foo').dialog({
    buttons:
    {
        translations['ok']: function() { alert('foo-ok'); },
        translations['cancel']: function() { alert('foo-cancel'); }
    }
});

// working
jQuery('#bar').dialog({
    buttons:
    {
        "Ok": function() { alert('bar-ok'); },
        "Cancel": function() { alert('bar-cancel'); }
    }
});

이를 가변 배열 키와 함께 작동시키는 방법이 있습니까?

도움이 되었습니까?

해결책

당신은 이것을 시도 할 수 있습니다. 도움이 될 수 있습니다.

var buttonsOpts = {}
buttonsOpts[translations["ok"]] = function ....
buttonsOpts[translations["cancel"]] = function ....
jQuery('#bar').dialog({
   buttons : buttonsOpts
});

도움이되기를 바랍니다!

다른 팁

jQuery('#bar').dialog({
   buttons : [
       {
        text: translations.ok,
        click: function(){}
       },
       {
        text: translations.cancel,
        click: function(){}
       },
   ]
});

나는 이것이 4 살이라는 것을 알고 있지만, 제가 가지고있는 문제의 가장 큰 결과입니다. 여기 내 노동의 결과가있었습니다.

마우스 또는 키보드 이벤트에서 함수를 호출하고 (괄호없이) 함수를 참조하고 버튼을 정의하거나 비워지고 제목을 설정하고 표시 할 텍스트를 설정하십시오.

function confirmDialogue(fn, value, ok, cancel, title, text){
    if (typeof ok == "undefined" || ok == ""){ok = "Ok";}
    if (typeof cancel == "undefined" || cancel == ""){cancel = "Cancel";}
    var buttonsOpts = {};
    buttonsOpts[ok] = function() {fn(value);$( this ).dialog( "destroy" );}
    buttonsOpts[cancel] = function() {$( this ).dialog( "destroy" );}

    var NewDialog = $('<div id="dialogConfirm"><p>' + text + '</p></div>');
    NewDialog.dialog({
        title: title,
        dialogClass: "dialogue",
        modal: true,
        height: "auto",
        width: "auto",
        show: true,
        hide: true,
        close: function(){$(this).dialog('destroy');},
        buttons: buttonsOpts
    });
    return false;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top