如何使用ember.js模板进行自动对焦? [英] How to use autofocus with ember.js templates?

查看:91
本文介绍了如何使用ember.js模板进行自动对焦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的ember.js文本字段,我正在尝试添加自动对焦

I have a simple ember.js text field and I'm trying to add autofocus

{{view PersonApp.SearchField placeholder="search..." valueBinding="searchText"}}

PersonApp.SearchField = Ember.TextField.extend({

});

我可以在javascript中添加这个,还是像模板本身的属性一样简单? / p>

Can I add this in the javascript or is at as simple as a attribute in the template itself?

推荐答案

更新:

Ember的版本现在支持这种内置的,所以您不再需要重新打开TextField来添加一个attributeBinding。截至2014年1月( fdfe8495 ),您只需使用HTML5自动对焦属性在您的模板中:

More recent versions of Ember now have support for this built in, so you no longer need to reopen TextField to add an attributeBinding. As of January 2014 (commit fdfe8495), you can simply use the HTML5 autofocus attribute in your template:

{{input value=search type="text" placeholder="Search" autofocus="autofocus"}}

这是一个简单的jsfiddle演示

上一个解决方案:

您还可以重新打开TextField以允许您绑定autofocus属性:

You can also reopen TextField to allow you to bind the autofocus attribute:

Ember.TextField.reopen({
  attributeBindings: ['autofocus']
}); 

然后在您的模板中:

{{input value=search type="text" placeholder="Search" autofocus="autofocus"}}

这篇关于如何使用ember.js模板进行自动对焦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆