Ember.js自动对焦于刚刚创建的模板

时间:2013-02-20 14:13:55

标签: javascript ember.js

Ember是否可以将焦点设置在刚创建的模板上?

  <script type="text/x-handlebars" data-template-name="foo">
    {{#linkTo "foo.bars" class="success radius button"}}GET ALL THE BARS{{/linkTo}}
    {{outlet}}
  </script>

如何将注意力设置在新的foo/bars模板上?

1 个答案:

答案 0 :(得分:4)

你试过scrollIntoView吗?您可以创建一个在渲染后在其元素上调用它的视图:

App.FooFoo = Ember.View.extend({
  templateName: 'foo',

  didInsertElement: function() {
    var el = this.$()[0];
    el.scrollIntoView();
  }
});