2014-03-25 44 views
1

http://jsbin.com/qoyudape/1/edit灰烬模板模型更新

后不更新尽管使用.pushObject()模板没有更新。我注意到它会更新,如果改为this我在模板中使用modelcontent;

什么是this在视图中指的是如果不是模型?是否有可能使用this而不是modelcontent

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")); 
    } 
    } 
}); 

模板:

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

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

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

回答

1

this所指的控制器。顺便说一句,一个简单的方法来发现,是在您的模板中做{{log this}}另请参阅:http://emberjs.com/guides/understanding-ember/debugging/

我真的不确定它是检查truthy/falsy,但你总是可以使用长度。一旦找到它我会更新。

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

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

+0

但为什么它的工作在初始加载,但更新不工作? – Tomas

+0

我不确定它是否在技术上有效,我认为它可能会在集合上观察其他内容并发现它是虚假的。 – Kingpin2k