[英]Statement declaration using variable?
So I have this situation: 所以我有这种情况:
jsvars['delete'] = "Delete";
$.modal({
content: $("#delete").html(),
title: jsvars['delete_category'],
buttons: {
jsvars['delete']: function(win) {
// Do something
},
Cancel: function(win) { win.closeModal(); }
}
});
This prints an error, the code doesn't allow the jsvars['delete']
to be there when declaring buttons. 这会打印错误,代码在声明按钮时不允许
jsvars['delete']
出现。 I tried eval and lots of tricks, but I just don't have any idea how to get that working. 我尝试了评估和许多技巧,但我只是不知道如何使它起作用。 I tried googling also, but i am not sure of the terms how to search.
我也尝试使用谷歌搜索,但不确定如何搜索。
So how can I allow it to use variables there? 那么如何允许它在其中使用变量? I need to use the jsvars-array, because I keep translations there.
我需要使用jsvars-array,因为我在那里保留翻译。
you need to make sure the variable gets named at runtime or it wont work. 您需要确保变量在运行时被命名,否则将无法工作。
this should do it. 这应该做到。
jsvars['delete'] = "Delete";
buttonObj = {};
buttonObj[jsvars['delete']] = function(win) { // Do something };
buttonObj.cancel = function(win) { win.closeModal(); }
$.modal({
content: $("#delete").html(),
title: jsvars['delete_category'],
buttons: buttonObj
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.