简体   繁体   中英

How can i create ember handlebar helper for true or false condition

Here is my handlebar template...

{{#idType}}
  <label>{{unbound Model.viewData.name}}<span class="redTxt">*</span></label>
  <input type="text" name="" id="{{unbound Model.viewData.name}}">
{{/idType}}

In Ember view, I created one helper method like

Em.Handlebars.registerHelper("idType", function() {
    if(Model.viewData.selectGender === "Gender") {
        return true;
    } else {
        return false;
    }
});

Here If it is true, then its displays true instead of my label and textfield. Can you please help me to find a solution for this?

Define a computed property in your controller/model as follows, you don't need a helper method for this

requiredGender: function(){
  //returning a boolean value
  return this.get('viewData.selectGender') === "Gender";
}.property('viewData.selectGender') // defining dependencies

{{#if requiredGender}}
  TRUE
{{else}}
  <label>{{unbound Model.viewData.name}}<span class="redTxt">*</span></label>
  <input type="text" name="" id="{{unbound Model.viewData.name}}">
{{/if}}

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