简体   繁体   中英

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.

The previous coder used an {{#ifCond}} to toggle what 'selected'. This is my component.

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

Here is the div i want converted to my component

<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.

{{#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. The whole idea is to pull that out of handlebars anyways. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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