I’m using jQuery with Django to do some stuff with tables. I have the following javascript:
$("#pending_table").tablesorter({
headers: {5 + {{somevariable}}: {sorter:false},6 + {{somevariable}}: {sorter:false}}
});
(I omitted a bunch of other options that are irrelevant)
The part that’s causing trouble is the addition in the headers dictionary definition. Looking at the source of the resulting webpage, I can see that {{somevariable}} converts properly to its value of 4, so it’s not a Django-related issue.
In summary: “5 + 4 : value” does not work, “9 : value” does work.
I’m assuming I’m getting the syntax of the javascript wrong somehow.
Help?
Javascript object literals only allows literals as keys. In other words, you cannot have a calculated expression as a key. For example, this is unallowed:
That said, you can do this to circumvent that restriction:
In your case, it looks like you want to do something like this: