开发者

Jquery templates: How to access data object from array

开发者 https://www.devze.com 2023-03-20 16:30 出处:网络
This example does not work for me: 开发者_如何转开发 $.tmpl(\'<span class=\"ui-button ui-widget ui-icon-${data}\">\\

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消