2009-08-31 4 views
22

jquery UI 대화 상자의 단추에 대한 번역 된 레이블이 변수에 있습니다.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 
}); 

는 희망이 도움이 : 당신이 시도 할 수

+0

'translatinos' 철자가 의도적입니까, 아니면 오타입니까? –

답변

38

, 그것은 도움이 될 수있다!

+0

이 방법은 효과가 있습니다 - 며칠 전 동일한 문제가 있습니다 - 그렇게하는 것이 좋습니다. –

+0

이 한 시간 만 시도했지만 다른 구문을 사용했습니다 ... 다시 시도하겠습니다.) – Karsten

+0

괜찮습니다. 구문은 다음과 같이 작동합니다.) 감사합니다. – Karsten

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

나는 이것이 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; 
}