[英]Retrieve a value from a Javascript object
How do I retrieve a value from the object below? 如何从下面的对象中检索值?
var recipe= {};
recipe[0, 'prodmem_active.tpoint_prod[0].setpoint'] = 1600;
recipe[0, 'prodmem_active.tpoint_prod[1].setpoint'] = 1300;
recipe[1, 'prodmem_active.tpoint_prod[0].setpoint'] = 1600;
recipe[1, 'prodmem_active.tpoint_prod[1].setpoint'] = 1300;
recipe[2, 'prodmem_active.tpoint_prod[0].setpoint'] = 1500;
recipe[2, 'prodmem_active.tpoint_prod[1].setpoint'] = 1200;
eg alert(recipe[1]['prodmem_active.tpoint_prod[1].setpoint'])
doesn't work. 例如
alert(recipe[1]['prodmem_active.tpoint_prod[1].setpoint'])
不起作用。
You have to assign the value correctly in the first place. 首先,您必须正确分配值。
The comma operator evaluates as its right hand side. 逗号运算符的取值为右手边。
This: 这个:
recipe[0, 'prodmem_active.tpoint_prod[0].setpoint'] = 1600;
Means the same as: 意思是:
recipe['prodmem_active.tpoint_prod[0].setpoint'] = 1600;
You are trying to create a new object and then assign a value to one of the new objects properties. 您试图创建一个新对象,然后将值分配给新对象属性之一。
recipe[0] = {};
recipe[0]['prodmem_active.tpoint_prod[0].setpoint'] = 1600;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.