内插值与HTML属性Underscore.js [英] Interpolate inside html attributes with Underscore.js
本文介绍了内插值与HTML属性Underscore.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要建Backbone.js的使用,Underscore.js,HAML和CoffeeScript的应用程序。
I'm building an application using Backbone.js, Underscore.js, HAML, and Coffeescript.
我遇到的问题是让变量里面的html元素属性插值。
The problem I'm having is getting variables to interpolate inside of html element attributes.
<% _.each(collection.models, function(document) { %>
%tr
%td
%input{:type => 'checkbox', :name => "documents[]", :value => "<%= document.attributes.id %>"}
%td <%= document.attributes.id %>
%td <%= document.attributes.name %>
<% } %>
<% }); %>
对象的值内适当地显示&LT; TD方式&gt;
,而不是输入的值属性内
The object's values are displaying properly inside of the <td>
, but not within the input's value attribute.
时的插值元素的属性里面可能吗?我没能找到解决的办法。
Is interpolation inside of an element's attributes possible? I was not able to find a solution.
感谢
推荐答案
这个问题的解决方案是使用HAML的:escape_attrs
选项
The solution to this problem is to use HAML's :escape_attrs
option.
Haml::Engine.new(template, :escape_attrs => false).render
这篇关于内插值与HTML属性Underscore.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文