【发布时间】:2019-11-29 17:10:00
【问题描述】:
第一个和第二个代码不运行。但是,当我写一个数字时,第三个代码会运行。我为'number'写一个值,例如这样,var number = 1;.
这个代码我试过了,
alert("<%- graphic[0].graphics_objects[' + number + ']._id -%>");
但它没有..我怎样才能在里面写一个索引号?
第一个代码:
alert("<%- graphic[0].graphics_objects[number]._id -%>");
第二个代码:
alert("<%- graphic[0].graphics_objects[<%=number%>]._id -%>");
第三个代码:
alert("<%- graphic[0].graphics_objects[1]._id -%>");
【问题讨论】:
-
alert("<%= graphic[0].graphics_objects[0]._id %>");当我用' -
我们不知道您的
graphic对象/数组是什么样子或number来自哪里。提供minimal reproducible example
标签: javascript arrays node.js string ejs