2014-03-25 45 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