Jquery templates: How to access data object from array
This example does not work for me:
开发者_如何转开发$.tmpl('<span class="ui-button ui-widget ui-icon-${data}">\
${data}</span>', \
["info", "delete"]\
)
since it will return nothing in place of ${data}. I also tried with ${item} which gave me same result.
What i want to achieve, is to insert the text "info" in the first generated span and "delete" in the next span.
As a workaround, i can pass in objects like so:
[{name: "info"}, {name: "delete"}]
and access them with ${name}
directly.
But how to i make it work without the workaround?? What is the correct syntax for getting element in aray?
You forgot to add one $
sign before data.
Change ${data}
to ${$data}
Try this:
$.tmpl('<span class="ui-button ui-widget ui-icon-${$data}">${$data}</span>', ["info", "delete"])
Working example @ http://jsfiddle.net/ythSP/
精彩评论