入门指南 获取Ember 概念 对象模型 应用 模板 路由 组件 控制器 模型 视图 枚举 测式 配置Ember.js COOKBOOK 理解Ember.js

发布于 2015-08-18 16:34:28 | 217 次阅读 | 评论: 0 | 来源: 网络整理

问题

当从一个页面跳转到另外一个页面时,页面滚动条总是停留在同样的位置。例如,如果访问了一个显示了很长列表的页面,并且滚动到页面的底部,这时又切换到另外一个具有长列表的页面,会发现页面的滚动条位置并没有被重置。

解决方案

添加下面的Mixin到受影响的路由:

 
1
2
3
4
5
6
App.ResetScroll = Ember.Mixin.create({
  activate: function() {
    this._super();
    window.scrollTo(0,0);
  }
});
 

只要想在activate方法中做点什么,就需要在一开始的时候调用this._super()

 
1
2
3
4
5
6
7
App.IndexRoute = Ember.Route.extend(App.ResetScroll, {
  //I need to do other things with activate 
  activate: function() {
    this._super.apply(this, arguments); // Call super at the beginning
    // Your stuff
  }
});
 

示例

Ember Starter Kit

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务