如何以一个jQuery元素的形式访问Ember输入? [英] How can I access an Ember input as a jQuery element?
问题描述
这是我的jsbin作为一个例子:
http://jsbin.com/umodir/1/edit
http:// jsbin .com / efatut / 2 / edit
您的服务器应该返回在控制器上设置可以观察到的属性的内容。我做的很简单,称之为错误。
var App = Ember.Application.create();
App.ApplicationController = Ember.ObjectController.extend({
error:false,
submit:function(){
alert('我想设置焦点在电子邮件输入栏现在...');
this.set('error',true);
}
});
App.ApplicationView = Ember.View.Extend({
focusEmail:function(){
if(this.get('controller.error')){
这个$('input [type = text]')。focus();
}
} .observes('controller.error')
});
如果您想要真正想要使用Ember.Component,如 {{eb-input focuson =error}}
,当控制器的错误属性更改时,将自动聚焦。
I have a simple form in Ember which submits to a server and returns a response. On a failed response, I want to re-focus on the input field. Is there a way to access the field in my controller using the value binding?
Here's my jsbin as an example:
http://jsbin.com/umodir/1/edit
http://jsbin.com/efatut/2/edit
Your server should return something that sets a property on your controller that you can observe. I made it pretty simple and called it "error".
var App = Ember.Application.create();
App.ApplicationController = Ember.ObjectController.extend({
error: false,
submit: function() {
alert('I want to set a focus on the email input field now...');
this.set('error', true);
}
});
App.ApplicationView = Ember.View.Extend({
focusEmail: function() {
if (this.get('controller.error')) {
this.$('input[type=text]').focus();
}
}.observes('controller.error')
});
If you wanted to get really fancy you could use an Ember.Component like {{eb-input focuson="error"}}
that would automatically focus when the controller's "error" property changed.
这篇关于如何以一个jQuery元素的形式访问Ember输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!