我希望将变量插入对象键结构中,但我只是获得变量名称而不是变量值。
var winnerId = 10;
var loserId = 11;
newMessage.setMessageData({
winnerId : {
"status" : "win",
"choice" : playerData[winnerId]["currentChoice"],
"newScore" : playerData[winnerId]["score"]
},
loserId : {
"status" : "lost",
"choice" : playerData[loserId]["currentChoice"],
"newScore" : playerData[loserId]["score"]
}
});
答案 0 :(得分:4)
您应该使用computed-property-names:
<div id="nav_box">
<!--nav box open-->
<div id="box1">
<img class="lilylink l1" src="lilypad.png" alt="lilypad 1">
<div class="overlay">
<span class="hovering">Hello!!!</span>
</div>
</div>
<div id="box2">
<img class="lilylink l2" src="lilypad.png" alt="lilypad 2">
<div class="overlay">
<span class="hovering">Hello 2</span>
</div>
</div>
<div id="box3">
<img class="lilylink l1" src="lilypad.png" alt="lilypad 3">
<div class="overlay">
<span class="hovering">Hello 3</span>
</div>
</div>
<div id="box4">
<img class="lilyink l2" src="lilypad.png" alt="lilypad 4">
<div class="overlay">
<span class="hovering">Hello 4</span>
</div>
</div>
</div>
<!--nav box close-->