来自变量的Javascript属性 [英] Javascript property from variable

查看:70
本文介绍了来自变量的Javascript属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JavaScript代码有问题。我现在开始处理一些更复杂的事情,似乎在网上找到了一些答案,但不幸的是我无法修复它。问题是:

I have a problem with my JavaScript code. I'm starting with some more complex things right now, seemed to find some answers on the net, but unfortunately I can't get it fixed. The problem is:

我想要变量 sGetMobileField ValMob 获取参数,但是这样不起作用:

I want the variables sGetMobileField and ValMob to get in the parameters, but like this it isn't working:

var oFieldValues = { sGetMobileField:) { Value: ValMob } };

变量似乎不能用作对象属性。有人可以帮我解决吗?

Variables don't seem to work as a object property. Anybody can help me fix it?

谢谢,
Dane

Thanks, Dane

推荐答案

试试这个

var oFieldValues = { };
oFieldValues[ sGetMobileField ] = { Value: ValMob };

您可以将变量用作属性标识符,但不能在对象文字中使用。您必须先创建对象,然后可以使用

You can use variables as property identifiers, but not inside an object literal. You have to create the object first, and may then add dynamic properties using

obj[ varToHoldPropertyName ] = someValue;

这篇关于来自变量的Javascript属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆