[英]underscore js template if check on a variable
我正在嘗試使用underscore.js模板方法來呈現一些數據,所以基本上這就是我要在偽代碼中執行的操作
if (url is not null) {
<div>
<img src=url />
</div>
}
我需要在下划線js模板中執行此檢查,但是我不確定以下內容是否合法,棘手的部分是url也是模板變量
<% if (<%=url%>) { %>
<img src=<%=url%> />
<% } %>
救命?
在javascript上:
var myTmpl = _.template(foo);
myTmpl.tmpl({url: 'foo.com'});
在模板上:
<% if (url) { %>
<img src=<%=url%> />
<% } %>
請記住:當您使用<%時,您只是在編寫javascript;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.