Javascript 重新访问时,Emberjs查询参数不起作用

Javascript 重新访问时,Emberjs查询参数不起作用,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我有一个用户路由,其参数如下: http://localhost:8000/#/users/index?page=2&pageSize=1 问题是,如果我转到第2页,然后转到一个完全不同的路线,然后再回到 http://localhost:8000//users/index 它仍然显示第2页,而不是默认的第1页。我花了一天的时间来追踪这件事,但还是弄不明白-请帮忙 这就是流程: 转到向其发出请求的用户页面http://localhost:8000/api/users?page=1&pa

我有一个用户路由,其参数如下:

http://localhost:8000/#/users/index?page=2&pageSize=1
问题是,如果我转到第2页,然后转到一个完全不同的路线,然后再回到 http://localhost:8000//users/index 它仍然显示第2页,而不是默认的第1页。我花了一天的时间来追踪这件事,但还是弄不明白-请帮忙

这就是流程:

转到向其发出请求的用户页面http://localhost:8000/api/users?page=1&pageSize=1&query=&status=active 正确的

单击第2页,请求http://localhost:8000/api/users?page=2&pageSize=1&query=&status=active 正确的

单击其他路线无请求-正确

单击没有查询参数的用户链接,请求http://localhost:8000/api/users?page=2&pageSize=1&query=&status=active 错误-url没有查询参数,应默认为第1页

再次单击另一条路线

再次单击用户链接,并向http://localhost:8000/api/users?page=1&pageSize=1&query=&status=active 正确,页面已正确设置为1,正如它本应设置的那样

这里有一些代码给你一个想法

App.UsersIndexRoute = App.AuthenticatedRoute.extend(App.PaginationRouteMixin,{
  queryParams: {
    query: {refreshModel: true},
    status: {refreshModel:true}
  },
  model: function(params) {
    return this.store.find('user',params);
  },
});

App.UsersIndexController = Em.ArrayController.extend(App.PaginationMixin,{
  needs:['users'],
  queryParams: ['query','status'],
  query: '',
  status:'active'
});

App.PaginationRouteMixin = Em.Mixin.create({
  queryParams: {
    page: {refreshModel:true},
    pageSize: {refreshModel:true},
  }
});

App.PaginationMixin = Em.Mixin.create({
  pagination: function () {
    if (this.get('model.isLoaded')) {
      modelType = this.get('model.type');
      return this.get('store').typeMapFor(modelType).metadata.pagination;
    }
  }.property('model.isLoaded'),

  pages: function() {
    var availablePages = this.get('availablePages'),
    pages = [],
    page;
    for (i = 0; i < availablePages; i++) {
      page = i + 1;
      pages.push({ page_id: page.toString() });
    }
    return pages;
  }.property('availablePages'),

  currentPage: function() {
    return parseInt(this.get('pagination.CurrentPage'), 10) || 1;
  }.property('pagination'),

  nextPage: function() {
    var nextPage = this.get('currentPage') + 1;
    var availablePages = this.get('availablePages');
    if (nextPage <= availablePages) {
      return Ember.Object.create({id: nextPage});
    }else{
      return Ember.Object.create({id: this.get('currentPage')});
    }
  }.property('currentPage', 'availablePages'),

  prevPage: function() {
    var prevPage = this.get('currentPage') - 1;
    if (prevPage > 0) {
      return Ember.Object.create({id: prevPage});
    }else{
      return Ember.Object.create({id: this.get('currentPage')});
    }
  }.property('currentPage'),

  availablePages: function() {
    return this.get('pagination.PageCount');
  }.property('pagination'),

  pageSize:"10",
  page:"1",
  queryParams:['page','pageSize'],
  actions:{
    setPage:function(pageId){
      this.set('page', pageId);
    }
  }

});

谢谢。

查询参数是否存储在某种服务中?如果是这样的话,我打赌你需要清理它。你对路由的mixin的扩展不意味着你正在覆盖queryParams对象的mixin值吗?这是有意的吗?我也很想看看你的电话链接。您是否100%确定他们没有在链接上编码任何查询参数?另外,您似乎没有在控制器中的queryparams中添加page和pageSize。你把它漏掉是故意的吗?为什么不从更小、更简单的开始,慢慢引入功能,一次一块地测试每一位呢?然后您就知道哪里出错了。@mingos查询参数没有存储在其他任何地方。