Ember.js 启动模糊/聚焦某些属性更改
我的视图中有一个Ember.js 启动模糊/聚焦某些属性更改,ember.js,Ember.js,我的视图中有一个Ember.TextField。我希望当应用程序中的某个属性发生更改时,该字段能够聚焦。我已经学会了如何将回调绑定到焦点事件,但是是否有任何方法可以基于绑定启动字段的焦点?我认为简单的fiddle可以满足您的要求 完整性代码: window.App = Ember.Application.create(); App.model = Ember.Object.create({ someProp: 123, }); App.MyTextField = Ember.Tex
Ember.TextField
。我希望当应用程序中的某个属性发生更改时,该字段能够聚焦。我已经学会了如何将回调绑定到焦点事件,但是是否有任何方法可以基于绑定启动字段的焦点?我认为简单的fiddle可以满足您的要求
完整性代码:
window.App = Ember.Application.create();
App.model = Ember.Object.create({
someProp: 123,
});
App.MyTextField = Ember.TextField.extend({
value: 'foo',
autoFocus: function () {
if (App.model.someProp === "42") {
this.$().focus();
}
}.observes('App.model.someProp')
});
HTML:
{{view App.MyTextField}
尝试将此字段更改为“42”,并查看焦点是否移动。
{{view Ember.TextField valueBinding=“App.model.someProp”}
完美。谢谢余烬以几种不同的方式处理绑定,有时我发现我完全忘记了将观察者作为一种选择。
<script type="text/x-handlebars">
{{view App.MyTextField}}
</script>
<br/>Try changing this field to '42' and see that the focus moves.
<script type="text/x-handlebars">
{{view Ember.TextField valueBinding="App.model.someProp"}}
</script>