Tomas
Tomas

Reputation: 1467

Ember template doesn't update after model update

http://jsbin.com/qoyudape/1/edit

Despite using .pushObject() template doesn't update. I've noticed it DOES update, if instead this I use model or content in template;

What is this in view is referring to if not model ? Is it possible to get it working using this and not model or content ?

var App = Ember.Application.create();

App.ApplicationRoute = Ember.Route.extend({
  model: function(){
    return Ember.A();
  }
});

App.ApplicationController = Ember.ArrayController.extend({
  actions: {
    update: function(){
      this.get("model").pushObject( Ember.Object.create({a:"b"}) );
      console.log( this.get("model") );
    }
  }
});

template:

<script type="text/x-handlebars">

    <button {{action "update"}}>update</button>
    <br><br>

    {{#if this}}
      array not empty
    {{else}}
      array empty
    {{/if}}
  </script>

Upvotes: 1

Views: 760

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

this is referring to the controller. btw, an easy way to find that out is to do {{log this}} in your template see also: http://emberjs.com/guides/understanding-ember/debugging/.

I'm not actually sure what it's checking to be truthy/falsy, but you can always just use length. I'll update once I find it.

{{#if this.length}}
  array not empty
{{else}}
  array empty
{{/if}}

http://jsbin.com/qoyudape/3/edit

Upvotes: 1

Related Questions