简体   繁体   English

自定义车把,如果不等于助手

[英]Handlebars custom if equals helper not compiling

I've added a custom helper in Handlebars to accomplish an if == "some string" type helper. 我在车把中添加了一个自定义帮助器,以完成if == "some string"类型的帮助器。 The helper code is this: 辅助代码是这样的:

Handlebars.registerHelper('if_eq', function(a, b, opts) {
    if(a == b) // Or === depending on your needs
        return opts.fn(this);
    else
        return opts.inverse(this);
});

The template is this: 模板是这样的:

<div id="appStoreParametersModal" class="modal-dialog">
    <div class="modal-content appStoreParametersModal">
        <div class="modal-header hypersignModalHeader">
            <h3>{{appName}}</h3>
        </div>
        <div class="modal-body">
            <div id="app-params">
                {{#each appParm}}
                <form>
                    {{#if_eq uiControlType "text"}}
                    <div class="form-group">
                        <label for="{{qsName}}">{{uiName}}</label>
                        <input type="text" class="form-control" id="{{qsName}}" placeholder="{{uiName}}"/>
                    </div>
                    {{else if_eq uiControlType "dropdown"}}
                    <div class="form-group">
                        <label for="{{qsName}}">{{uiName}}</label>
                        <select class="form-control" id="{{qsName}}">
                            {{#each defaultVals}}
                                <option value="{{value}}">{{displayName}}</option>
                            {{/each}}
                        </select>
                    </div>
                    {{/if_eq}}
                </form>
                {{/each}}
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-warning cancel" data-dismiss="modal" id="cancel">Cancel</button>
            <button type="button" class="btn btn-success" id="appStoreNext">Next</button>
        </div>
    </div>
</div>

I'm getting this error: 我收到此错误:

Uncaught Error: if_eq doesn't match each 未捕获的错误:if_eq与每个都不匹配

It seems to be a problem with using the {{else}} , because if I only use the if_eq helper without an else , then it works fine. 使用{{else}}似乎是一个问题,因为如果我仅使用if_eq帮助程序而不使用else ,那么它将正常工作。 I'm pretty new to Handlebars, so I'm sure I'm missing something stupid. 我对Handlebars很陌生,所以我确定我缺少一些愚蠢的东西。

if_eq doesn't match if您有{{#if_eq stuff "stuff"}}时, if_eq doesn't match if抛出,但是您在{{/if}}而不是{{/if_eq}}错误地结束了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM