0

私はphpから来ました.elseステートメントのような代替構文を正しくすることができます.

<?php if(): ?>
    // conditional html goes here
<?php endif;?>

私の質問は、次のようなバックボーン ビューで同じことを行う方法があるかどうかです。

<% if(condition): %>
    html code goes here ;

<% endif; %>
4

2 に答える 2

1

デフォルトのUnderscore テンプレートを使用している場合:

<% if(condition) { %>
    HTML goes here
<% } %>

{andまたは を忘れないでください}。めちゃくちゃになってしまいます。

デモ: http://jsfiddle.net/ambiguous/W33Tw/

于 2013-03-28T18:47:49.123 に答える
0

この質問は、バックボーンで使用しているテンプレート ソリューションでタグ付けする必要があります。ハンドルバー (すばらしいhttp://handlebarsjs.com/ ) を使用している場合は、次の方法でそれを行うことができます。

{{#if contextPropertyThatEvaluatesSanelyAsABoolean}}
  your html!
{{else}}
  different html!
{{/if}}

次に、次のようなコンテキストを渡します。

$(@el).html(this.template({
  contextPropertyThatEvaluatesSanelyAsABoolean: true
}))

または、coffeescript を使用している場合:

$(@el).html @template
  contextPropertyThatEvaluatesSanelyAsABoolean: true

他のテンプレート言語にも同様のソリューションがあります。

于 2013-03-28T18:17:21.447 に答える