Question

I set a simple boolean (isEditing) in the 'categories' controller to equal 'true' when the {{action "edit" this}} button is clicked.

The variable will not set itself to true when 'edit' is clicked. I console.log'd to make sure 'edit' knew i was clicking it, and it did. This seems so simple in the emberjs website and i don't know why im having such trouble with now.

categories controller

VpcYeoman.CategoriesController = Ember.ArrayController.extend({
    isEditing: false,
    actions: {
        editingyeah: function(){
            console.log('Testing console'); //this works
            this.set('isEditing', true); //this doesnt change to true since the {{Else}} is what is being rendered.
        }        
    },

});

categories.hbs

    {{#each}}
      <tr class="people-list">
        <td>
          {{#if isEditing}}
          {{view Ember.TextField valueBinding=name}}
          NOOOOOOOO
          {{else}}
          <div class="category-text"> 
          {{view Ember.TextField valueBinding=name}}
            {{#linkTo 'category' this}}
              {{name}}
            {{/linkTo}}
          </div>
          {{/if}}  
          <img class="table-img" src="images/x.png">
          <img class="table-img" {{action "editingyeah" this}} src="images/pencil-grey.png">          
        </td>
      </tr>
    {{/each}}
Was it helpful?

Solution

It's because you are looping through each category, so the context within the each helper is your category. It's looking for an isEditing property on the category, not the one you have in the controller.

Since you are passing the category in to the action, you can access it as an argument in the action's function, and set the property on the category instead:

actions: {
    editingyeah: function(category){
        category.set('isEditing', true);
    }        
}

OTHER TIPS

I saw your problem after I posted my comment. You don't have an isEditing variable defined in your scope. You're using the #each helper, which changes the scope of the template. You either have to keep the scope when using #each, or use a #with helper.

{{#each item in model}}
    {{! isEditing is available now }}
    {{! But you have to do item.name instead of name}}
{{/each}}

Or

{{#with this.isEditing as isEditing}}
    {{#each}} ... {{/each}}
{{/with}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top