2013-03-16 96 views
1

此代码不能正常工作,因为我想。调用对象属性与变量

var csd = {large10x10: 0} 
var nextitem = "large10x10"; 
buildings.push(nextitem,"black",a); 
csd.nextitem += 1;  

at csd.nextitem +=1我想把它加1到csd.large10x10。我怎么做?或者我可以通过Google找到答案?

感谢

+1

尝试'CSD [nextitem] + = 1'(或甚至'++ CSD [nextitem]')。 – DCoder 2013-03-16 11:55:24

回答

2

您需要访问它的值是nextitem没有一个名为nextitem财产。 在JavaScript中,这是用括号表示完成的。

尝试

csd[nextitem] += 1;  

这里是一个fiddle with the code working

+0

太棒了。谢谢! – Henrik 2013-03-16 11:56:12