javascript - xsl :attribute with condition and handlebars

标签 javascript xslt handlebars.js

我尝试使用 Handlebars 设置 xsl:attribute。 代码是:

<input type="text">
  {{#if_eq line_type 0}}
    <xsl:attribute name="disabled">true</xsl:attribute>
  {{/if_eq}}
</input>

但是这样的构造是行不通的。 有什么办法可以解决这个问题吗?

最佳答案

所以你需要添加如下内容:

JavaScript:

    Handlebars.registerHelper('equal', function(lvalue, rvalue, options) {
        if (arguments.length < 3)
            throw new Error("Handlebars Helper equal needs 2 parameters");

        if( lvalue!=rvalue ) {
            return options.inverse(this);
        } else {
            return options.fn(this);
        }
    });

在 HTML 模板中,例如:

<input type="text">
  {{#equal line_type 0}}
    <xsl:attribute name="disabled">true</xsl:attribute>
  {{/equal}}
</input>

希望能有所帮助。

编辑:

{{#equal line_type 0}}    
<input type="text">
        <xsl:attribute name="disabled">true</xsl:attribute>

    </input>
{{/equal}}

关于javascript - xsl :attribute with condition and handlebars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35193049/

相关文章:

javascript - 带有许多无序列表项的溢出 div 区域

xslt - 如何将字符串连接到 xsl :value-of select=". ..?

xslt - 如何选择从特定节点而不是根节点开始的文本节点的前面节点?

handlebars.js - 检查 Handlebars 助手是否已经存在?

javascript - Backbone Marionette - 如何渲染 CompositeView->CollectionView->ItemView

javascript - 想要在 jQuery Mobile 首次加载时显示对话框消息

javascript - 单击添加类(class),然后延迟删除类(class)

php - 了解 VBScript

xml - 如何通过 XSL 从现有 XML 文件中的字符串正确调用图像?

javascript - 错误 : Missing Helper in Handlebars. js