开发者

JavaScript acrobatics: How to declare an array, elements, and properties in one string

Given the following code:

eval('(mapping.' + binding.field + ' = eval("extVar") )');

where binding.field = "LPP开发者_Python百科[0].price" (a string) and extVar is the same value of "LPP[0].price"

How could you program the statement above to end up with:

mapping.LPP[0].price = LPP[0].price;

when mapping.LPP isn't defined yet? This code cycles through the Microsoft JQuery templates pulling variable names as strings from the tempaltes. When we reference properties in arrays, it throws up based on this code. It says that mapping.LPP[0] isn't defined.


if(!mapping.LPP) mapping.LPP = [];
mapping.LPP[0].price = LPP[0].price;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜