Javascript/Ember - Toggle Boolean Value of Variable

Ian S picture Ian S · Feb 21, 2014 · Viewed 15.9k times · Source

I know that there is the .set() method to set a boolean to true or false but I want to know if there a method like .set() except it Toggles the value of a boolean.

In this case the boolean isEditing is being set to 'true'.

isEditing:false,
actions: {
  edit: function(category){
    category.set('isEditing', true);
    console.log(this.get('isEditing'))
  },
}

Here is the html

{{#if isEditing}}
  <div class="category-text"> 
    {{view Ember.TextField valueBinding=name action="turnOffEditMode"}}
  </div>
{{else}}
  <div class="category-text"> 
    {{#linkTo 'category' this}}
      {{name}}
    {{/linkTo}}
  </div>
{{/if}}  

Answer

Jake Roby picture Jake Roby · Feb 21, 2014
this.toggleProperty('propertyName');

Edit: jsbin for proof