绑定视图与依赖 [英] Binding on view with dependency
问题描述
我正在使用视图将数据绑定到contentEditable div
,使用此问题的答案中找到的代码: Ember和HTML5 contenteditable属性
I am using a view to bind data to a contentEditable div
using the code found in the answer to this question: Ember and HTML5 contenteditable property
我有一个属性 abc
,我绑定它喜欢这样:
I have a property a.b.c
that I'm binding it to like so:
{{view App.ContenteditableView valueBinding="a.b.c"}}
正确更新 abc
当我输入它,并且当我修改 abc
时,它会自动更新。但是,当我将 a
更改为不同的对象时,它不会更新。也就是说,当 a
或 b
更改时,文本框需要更新,而不仅仅是 c
更改。
This correctly updates a.b.c
when I type in it, and it updates itself when I modify a.b.c
. However, It does not update when I change a
to a different object. That is, the text box needs to update when a
or b
changes, not just when c
changes.
如何完成?
推荐答案
如果您正确使用内置的设置器,Ember已经支持此功能。
Ember already supports this if you properly use the built in setters.
如果 a
扩展Ember如果 a
是一个POJO a.set('b',{c:'asdf'}) code> Ember.set(a,'b',{c:'asdf'})。
if a
extends Ember.Object a.set('b', { c: 'asdf'})
if a
is a POJO Ember.set(a, 'b', { c: 'asdf'})
.
另外使用valueBinding isn在必要的情况下,您可以写 value = abc
Additionally using valueBinding isn't necessary, you can just write value=a.b.c
在提供的示例中,我将文本框设置为 abc
In the provided example I set the text box to a.b.c
App.IndexRoute = Ember.Route.extend({
model: function() {
return {
a:{
b:{
c:'dog'
}
}
};
},
actions:{
change: function(){
Em.set(this.currentModel, 'a', {b:{c:'fdasdf'}});
}
}
});
示例: http://emberjs.jsbin.com/toticame/1/edit
这篇关于绑定视图与依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!