2015-12-02 111 views
0

我有聽的模型,看起來像一個計算的屬性:灰燼2.1輸入字段的改寫計算屬性

groups: function() { 
    let g = this.get('model.items.groups').map(function(obj) { return obj.group; }); 
    return g.join(','); 
    }.property('model.items.groups'), 

在我的模板,我有以下輸入字段:

{{input value=groups type="text" class="form-control" placeholder="Testme"}} 

我注意到,在通過UI提供輸入之後,Ember檢查器中groups的值成爲一個字符串,不再是計算屬性。我如何在Ember 2.1中避免這種情況,並只更新計算出的屬性?

+0

你是什麼意思_update計算出的property_? – spectras

回答

1

發生這種情況是因爲{{input}}幫助程序默認使用雙向綁定。在輸入字段中寫入時,它將寫入value屬性。

我一直在使用dockyard's one-way-input插件,默認情況下,它提供了一個單向綁定的輸入組件。

{{one-way-input 
    value=groups 
    update=(action 'updateSomething') 
}} 

然後在無論你正在使用的組件:

actions : { 
    updateSomething(value) { 
    //Do Something with the value and update model.items.groups? 
    } 
} 

這樣,該值總是從groups計算性能閱讀和操作會更新值的來源(而不是計算屬性)