Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have variables holding the translated labels for buttons inside a jquery ui dialog.

I cannot fill the button array key with the variable itself, and can't find any way to let it treat my variable just as string.

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

Is there any way to get this to work with variable array keys?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
227 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can try this, may be it helps:

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

Hope it helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...