简体   繁体   English

我想在Ember.Handlebars.helper中使用{{#if}}逻辑

[英]I want Handlebar {{#if}} logic inside of a Ember.Handlebars.helper

I am converting someone else's code to Handlebars.js and I'm stuck on converting this tag to its {{#handle-bar}}{{/handle-bar}} counterpart. 我正在将其他人的代码转换为Handlebars.js,但我坚持将其转换为{{#handle-bar}}{{/handle-bar}}对应代码。

The previous coder used an {{#ifCond}} to toggle what 'selected'. 先前的编码器使用{{#ifCond}}来切换“已选择”的内容。 This is my component. 这是我的组件。

{{#dropdown-item }}
    {{unbound this.itemName}}
{{/dropdown-item}}

Here is the div i want converted to my component 这是我想转换为组件的div

<div class="dropdownItem" {{bind-attr value=formField_DropdownItemID}}{{#ifCond formField_DropdownItemID value}} selected{{/ifCond}} >
    {{unbound this.itemName}}
</div>

My first thought was to just pop the div's logic into the the component, like the next example, but this gave me an error. 我的第一个想法就是像下面的例子一样,将div的逻辑弹出到组件中,但这给了我一个错误。

{{#dropdown-item bind-attr value=formField_DropdownItemID {{#ifCond formField_DropdownItemID value}} selected{{/ifCond}} }}
    {{unbound this.itemName}}
{{/dropdown-item}}

Any suggestions? 有什么建议么?

You can set those properties to compute. 您可以设置这些属性以进行计算。 The syntax would be: 语法为:

{{#dropdown-item selected=computedProperty value=formField_DropdownItemID}}

computedProperty can deal with your conditional logic. computedProperty可以处理您的条件逻辑。 The whole idea is to pull that out of handlebars anyways. 整个想法是无论如何都要将其拉出车把。 :) :)

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

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