0
我需要将(json)对象插入到页面中使用的数组中。我用jade使用nodejs,并假设下面的代码可能符合我的目的,但它不起作用。在页面脚本中使用玉的迭代
//this code is in the template:
script.
otherPlayers = {};
each player in playerList
otherPlayers["#{player.playerId}"] = !{JSON.stringify(#{player})};
在页面预期的结果是:
<script>
otherPlayers = {};
otherPlayers[0] = {"playerId": 0, "playerName": "Leo" };
otherPlayers[1] = {"playerId": 1, "playerName": "Daniel" };
otherPlayers[2] = {"playerId": 2, "playerName": "Lucas" };
</script>
任何暗示被广泛接受。 在此先感谢。
感谢它的工作原理 – NodeJsBeginner