检查在Ember Handlebar中的值等于块助手 [英] Check for a value equals to in Ember Handlebar If block helper
本文介绍了检查在Ember Handlebar中的值等于块助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查 ember.js 的If-block帮助器中的值是否相等?
{{#if person ==John}}
我们如何在手柄中执行以上操作?
解决方案
{{# if}}
helper只能测试属性,而不是任意表达式。因此,在这样的情况下,最好的事情是写一个属性来计算你想要测试的条件。
personIsJohn: function(){
return this.get('person')==='John';
} .property('person')
然后执行 {注意:如果你发现这太限制了,你也可以注册您自己的更强大的
如果
帮助。
How do we check for a value equality in ember.js's If-block helper?
{{#if person=="John"}}
How do we perform above in handlebars?
解决方案
The {{#if}}
helper can only test for properties, not arbitrary expressions. The best thing to do in cases like this is therefore to write a property computing whatever conditional you want to test for.
personIsJohn: function() {
return this.get('person') === 'John';
}.property('person')
Then do {{#if personIsJohn}}
.
Note: If you find this too limiting, you can also register your own more powerful if
helper.
这篇关于检查在Ember Handlebar中的值等于块助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文