Backbone.js的:在元素属性模板变量不起作用 [英] Backbone.js: Template variable in element attribute doesn't work

查看:266
本文介绍了Backbone.js的:在元素属性模板变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的模板:

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

但它不工作,而非{{}}成为输出HTML EN codeD。

But it doesn't work, instead the {{}} becomes html encoded in the output.

我如何prevent呢?

How do I prevent this?

推荐答案

假设你正在使用带有Backbone.js的(这实际上是来自Underscore.js)的默认模板引擎,那么语法是:

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>

假设 test_url 存在于数据对象要传递到模板。此外,请确保您传递一个普通的老JS对象( this.model.toJSON())的模板函数,否则该决议将不会发生。

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.

如果原来使用的是不同的模板引擎,请让我们知道它是什么引擎,并为我们的观点code被渲染的模板。

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.

这篇关于Backbone.js的:在元素属性模板变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆