开发者

Backbone.js: Template variable in element attribute doesn't work

开发者 https://www.devze.com 2023-04-10 17:51 出处:网络
I have the following template: <a href=\"{{test_url}}>Test</a> But it doesn\'t work, instead the {{}} becomes html enco开发者_运维知识库ded in the output.

I have the following template:

<a href="{{test_url}}>Test</a>

But it doesn't work, instead the {{}} becomes html enco开发者_运维知识库ded in the output.

How do I prevent this?


Assuming you are using the default templating engine that comes with Backbone.js (which actually comes from Underscore.js), then the syntax would be:

<a href="<%= test_url %>">Test</a>

Assuming that test_url exists in the data object you are passing to the template. Also, make sure that you are passing a plain old JS object (this.model.toJSON()) to the template function or else the resolution won't happen.

If it turns out you are using a different templating engine, please let us know what engine it is AND provide us with the view code that is rendering the template.

0

精彩评论

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