我有一些变量存储了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'); }
}
});
有没有办法让这个方法适用于可变的数组键?