You create an empty hash, like so:
var buttons = {};
then you use array-index notation to set the variable-key-named property:
var text1 = "Open";
var text2 = "Save";
var text3 = "Cancel";
buttons[text1] = function() { ... };
buttons[text2] = function() { ... };
buttons[text3] = function() { ... };
Then you pass that hash (which now has three properties, buttons.Open,
buttons.Save, buttons.Cancel) in the dialog init options:
elm.dialog({
buttons: buttons
});
- Richard
On Thu, Mar 12, 2009 at 3:19 AM, Tarjei Huse <[email protected]> wrote:
>
> Hi, this may be just me being bad at JS, but I got a dialog like this:
>
> elm.dialog({
> resizable: false,
> title: (caller.title) ? caller.title : formElement,
> buttons:{
> 'Ok' : function() {
> var form = $("#" + caller.nodeId + " form");
> var options = {
> 'beforeSubmit': function (data, form, options) {
> $(elm).dialog('close');
> delete(data.id);
> return true;
> },
> 'url':getMenuItemSavePointer(caller._id),
> 'type' : 'POST',
> 'dataType': 'json',
> 'success': onMenuItemSaveDone
>
> };
> form.ajaxSubmit(options);
> },
> 'Close' : function() {
> $(this).dialog('destroy');
> }
> }}
>
>
>
> Sometimes I want the 'Ok' text to be 'Save', other times I want it to be
> "Delete". How can I use a variable as a key to a hash?
>
> This is a bit a general JS quesion, I'm sorry for that, but I have tried
> to research this and haven't come up with a good way to do it.
>
> Regards,
> Tarjei
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---