0
我试图动态访问一个包含在字符串中的属性值的对象。示例如下:使用字符串变量的值作为对象参数访问器
var toolState = {
draw_point: false;
draw_line: false;
}
var dynamicText = "draw_point";
toolState.dynamicText = true; //here is the problem
我对JS相当陌生。对不起,如果这是一个愚蠢的问题。
谢谢
尝试'toolState [dynamicText]'。 – blex 2014-09-12 15:33:13
toolState [dynamicText]或toolState [“propertyName”] – 2014-09-12 15:33:27
[动态访问对象属性使用变量](http://stackoverflow.com/q/4244896/218196),可能[更多](http:// stackoverflow。 com/search?q =%5Bjavascript%5D + dynamic + property + variable) – 2014-09-12 15:34:49