var events = [
{id: 100,url: "mc.jsp?id=" + id},
{id: 200,url: "mc2.jsp?id=" + id},
{id: 300,url: "mc2.jsp?id=" + id}
]
When run, the url equals mc.jsp?id=undefined,
so how can assign the id (100) to the url to get the value of mc.jsp?id=100?
And also make the second url as mc2.jsp=200 and third one mc2.jsp?id=300
so I cannot make assignment outside the array.
You can’t access other properties in an object literal on constructions. You get an
undefinedbecause you have no variableid. You will need to use:or:
but you could define a getter:
which is very complicated and difficult to understand. Maybe it’s better to do something like this:
However, there should be no such problem. If you hardcode the numbers, why don’t you hardcode the urls? If you don’t want the redundancy, just don’t store the id two times and append it each time you need it.