我尝试使用 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/