2012-03-02 1 views
1

オブジェクトからビューを作成すると、オブジェクトのプロパティを変更するとビューのプロパティも変更されるようです。ビューのプロパティを変更すると、その変更はオブジェクトに反映されません。私は、双方向のバインディングがデフォルトの動作であると考えました。何か不足していますか?双方向バインディング使用変数はどのようにして作成しますか?

WidgetClass = Ember.Object.extend 
    address: 'widget address' 
    create_view: -> 
    # console.log this.name 
    view = Ember.View.create 
     someobj: this 
     addressBinding: 'someobj.address' 
     template: Ember.Handlebars.compile '{{address}}' 

    return view 

TextWidget = WidgetClass.create() 

view = TextWidget.create_view() 

view.append() 

view.set 'address', 'new new address' 
console.log (view.get 'address') 
console.log (TextWidget.get 'address') # I am expecting this output to be 'new new address' 

http://jsfiddle.net/rkitamura/2zsUX/

答えて

2

バインディングを塗布した後、すぐにそれらをテストするとき、あなたは追いつくためにエンバー実行ループを強制する必要があります。 view.set 'address', 'new new address'の前にEmber.run.sync()を追加してください。あなたのsetTimeout()コールはもはや必要ありません。

+0

ありがとうございました。 Ember.run.sync()を追加しようとしましたが、バインディングは期待通りに機能しました。 – Rocky

+0

喜んで助けてください。設定がすべて完了している場合は、その質問に回答としてマークしてください。 –

1

この場合、setPathを使用することが重要です。双方向バインディングは完全に機能します。

次のコードが機能します。

view.setPath 'someobj.address', 'new new address' 
console.log (TextWidget.get 'address') # this outputs 'new new address' correctly 
関連する問題