我来自php,我可以使用替代语法if else语句,如
<?php if(): ?>
// conditional html goes here
<?php endif;?>
我的问题是,是否有办法在骨干视图上做同样的事情,如
<% if(condition): %>
html code goes here ;
<% endif; %>
答案 0 :(得分:1)
答案 1 :(得分:0)
这个问题应该用您使用骨干网的任何模板解决方案进行标记。如果你使用的是把手(很棒http://handlebarsjs.com/),你可以用:
{{#if contextPropertyThatEvaluatesSanelyAsABoolean}}
your html!
{{else}}
different html!
{{/if}}
然后传入类似的上下文:
$(@el).html(this.template({
contextPropertyThatEvaluatesSanelyAsABoolean: true
}))
或者如果您使用的是coffeescript:
$(@el).html @template
contextPropertyThatEvaluatesSanelyAsABoolean: true
其他模板语言也有类似的解决方案。