本文介绍了是否可以通过条件或其他JavaScript作为参数在ember handlebars?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想传递一个真/假的声明到我的把手
I would like to pass a true/false statement to my handlebars
{{Gd-text-input label="Specify" name="Specify" key="entry.810220554" hideIf="entry.18110 === "Client""}}
如果变量entry.18110设置为Client
I would like hideIf to be true if the variable entry.18110 is set to "Client
推荐答案
,我希望hideIf为true >另一个答案不适用于Ember Handlebars,对于您的情况,您可以执行此操作。
The other answer does not work for Ember Handlebars, for your case you could do something like this.
组件
Component
App.HideableCompComponent = Em.Component.extend({
isHidden: function(){
var prop = this.get('hideIfProperty');
if(!prop) return false;
// allow lazy comparison? up to you
return this.get('content').get(prop) == this.get('hideIfValue');
}.property('hideIfProperty', 'hideIfValue')
});
模板
<script type="text/x-handlebars" data-template-name="components/hideable-comp">
{{#unless isHidden}}
I am a component I am not hidden!
{{else}}
I am hidden
{{/unless}}
</script>
使用
{{hideable-comp content=model hideIfProperty='length' hideIfValue=3}}
这篇关于是否可以通过条件或其他JavaScript作为参数在ember handlebars?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!