本文介绍了我怎么可以使用,如果再在其他骨干HBS模板文件,I M使用handelsbar模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用如果当时其他人在哈佛商学院的文件,如果 {{NumLikes}} 0 更大然后第一个图像其他2幅图像,所以我怎么可以使用Backbone.js的使用,如果再在其他HBS模板文件。
我使用handelsbar模板。

 < D​​IV>
        < DIV CLASS =COMM标签行>
            < D​​IV CLASS =后左面板>
                < D​​IV CLASS =图像容器后>
                 < IMG SRC ={{UserImageURL}}ALT =级=后的图像/>< / BR>
                &所述;%如果({{NumLikes}} = 0){%GT;
                    < IMG SRC =images/myCommunity/[email protected] =20HEIGHT =19ID =像-BTNNAME =样按钮>
                <%}其他{%GT;
                    < IMG SRC =images/myCommunity/[email protected] =20HEIGHT =19ID =像-BTNNAME =样按钮>
                <%}%GT;
                ({{NumLikes}})
                < / DIV>
            < / DIV>
            < D​​IV CLASS =身体后>
                < H5类=COMM标签,标题为>
                    <跨度类=导航屏幕ID ={{ID}}的风格=文本修饰:下划线;>
                        {{用户名}}
                    < / SPAN>
                    <跨度>
                          - &安培; NBSP;
                    < / SPAN>
                    <跨度>
                       {{format_date时间}}
                    < / SPAN>
                < / H5>
                {{信息}}
                < / DIV>
                < D​​IV CLASS =COMM-右面板>
                < A HREF =JavaScript的:无效(0);类=BTN-遵循NAME =跟随按钮>遵循< / A>
                    < A HREF =JavaScript的:无效(0);类=BTN-评论NAME =注释按钮> {{NumComments}} - 注释和LT; / A>
            < / DIV>
            < / DIV>        < / DIV>
    < / DIV>


解决方案

您不需要为这个自定义帮手,标准的 {{#如果}} 将做正确的事情以零。例如,这个模板:

 <脚本ID =T型=文本/ X-车把>
    {{#如果一}}一{{其他}}一个{{/ if}个}<!BR>
    {{#如果B}} B {{其他}} B {{/ if}个}<!BR>
< / SCRIPT>

这code:

  VAR T = Handlebars.compile($('#T')HTML());
$('身体')。追加(T({
    答:0,
    A:1
}));

会给你!一个 B 作为输出。演示:

您的模板应该这样说:

  {{#如果NumLikes}}
    < IMG SRC =images/myCommunity/[email protected] =20HEIGHT =19ID =像-BTNNAME =样按钮>
{{其他}}
    < IMG SRC =images/myCommunity/[email protected] =20HEIGHT =19ID =像-BTNNAME =样按钮>
{{/如果}}

i want to use if then else in hbs file, if {{NumLikes}} is greater than 0 then 1st image else 2nd image, so how i can use if then else in hbs template file using backbone.js.I am using handelsbar for template.

<div>
        < div class="comm-tab-row">
            <div class="post-left-panel">
                <div class="post-image-container">
                 <img src="{{UserImageURL}}" alt="" class="post-image"  /></br>     
                <% if ({{NumLikes}} = 0) { %>
                    <img src="images/myCommunity/[email protected]" width="20" height="19" id="like-btn" name = "like-Button" >               
                <% } else { %>
                    <img src="images/myCommunity/[email protected]" width="20" height="19" id="like-btn" name = "like-Button" >
                <%  } %>            
                ({{NumLikes}})          
                </div>
            </div>      
            <div class="post-body">
                <h5 class="comm-tab-heading">
                    <span class="navigate-screen" id="{{Id}}" style="text-decoration:underline;">
                        {{UserName}}
                    </span>
                    <span>
                         - &nbsp;
                    </span>
                    <span>
                       {{format_date Time ""}}
                    </span>
                </h5>
                {{Message}}
                </div>
                <div class="comm-right-panel">
                <a href="javascript:void(0);" class="btn-follow" name = "follow-button">FOLLOW</a>
                    <a href="javascript:void(0);" class="btn-comment" name = "comment-button">{{NumComments}} - COMMENT</a>
            </div>  
            </div>

        </div>
    </div>
解决方案

You don't need a custom helper for this, the standard {{#if}} will do the right thing with a zero. For example, this template:

<script id="t" type="text/x-handlebars">
    {{#if a}}a{{else}}!a{{/if}}<br>
    {{#if b}}b{{else}}!b{{/if}}<br>
</script>

and this code:

var t = Handlebars.compile($('#t').html());
$('body').append(t({
    a: 0,
    b: 1
}));

will give you !a and b as output. Demo: http://jsfiddle.net/ambiguous/tUAyZ/

Your template should say this:

{{#if NumLikes}}
    <img src="images/myCommunity/[email protected]" width="20" height="19" id="like-btn" name = "like-Button" >               
{{else}}
    <img src="images/myCommunity/[email protected]" width="20" height="19" id="like-btn" name = "like-Button" >
{{/if}}

这篇关于我怎么可以使用,如果再在其他骨干HBS模板文件,I M使用handelsbar模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:32