2016-08-04 7 views
-2

珍しいアルゴリアです。if else conditionを置く方法は?

アルゴリアヒットテンプレートのテンプレートが必要です。テンプレートのtext/htmlのスクリプトを参照してください。

<script type="text/html" id="hit-template"> 
    <div class="hit"> 
    <div class="hit-image"> 
     <img src="{{image}}" alt="{{name}}"> 
    </div> 
    <div class="hit-content"> 
     <h3 class="hit-price">${{final_price}}</h3> 
     <h2 class="hit-name">{{{_highlightResult.name.value}}}</h2> 
     <p class="hit-description">{{{_highlightResult.description.value}}}</p> 
    </div> 
    </div> 
</script> 

私は別のパラメータ{{retail_price}}を持っています。最終価格が小売価格よりも低い場合は、最終価格のみを表示します。そうでなければ、retail_priceストライクオフで両方を示してください。

<script type="text/html">にif else文の条件を書くにはどうすればいいですか?

+0

使用しているこのひげ剃りテンプレートエンジンですか? – sabithpocker

+1

この質問はJSとどのように関連していますか? – evolutionxbox

+0

ここで何が起こっているのか基本的な誤解があります。 html、javascript、templating langauges、およびバックエンドコードの違いを説明するのに役立つように、あなたと物理的に誰かまたはリアルタイムチャットが必要です。 – Relequestual

答えて

0

私はあなたのことを知っていませんが、すべてのパラメータを受け取り、条件を検証し、表示するデータをセットアップし、正しい情報でテンプレートを呼び出します。

function wrapper_template(image, final_price, _highlightResult){ 
    var show = final_price > 2000 ? true : false; 
    var html = template(yourTemplate, { image: image, price: final_price, result: _highlightResult }); 
return html; 
} 

希望!

0

これがMustacheテンプレートであると思われる場合は、JavaScriptスクリプトを作成してテンプレートが使用するフラグを作成する必要があります。このようなもの:

<script type="text/javascript"> 
    if(price < msrp) { 
    show_msrp = true; 
    } 
</script> 
<script type="text/html" id="hit-template"> 
    <div class="hit"> 
    <div class="hit-image"> 
     <img src="{{image}}" alt="{{name}}"> 
    </div> 
    <div class="hit-content"> 
     {{#show_msrp}} 
     <s><h4 class="hit-msrp">${{retail_price}}</h4></s> 
     {{/show_msrp}} 
     <h3 class="hit-price">${{final_price}}</h3> 
     <h2 class="hit-name">{{{_highlightResult.name.value}}}</h2> 
     <p class="hit-description">{{{_highlightResult.description.value}}}</p> 
    </div> 
    </div> 
</script> 
関連する問題