emberjs动态路段未定义

时间:2013-12-02 13:17:04

标签: javascript ember.js routes

我的emberJS动态细分路径有问题。 我的路由器:

App.Router.map(function () {
"use strict";
this.resource('signin', {path: '/'});
this.resource('index', {path: '/users'}, function () {
    this.route('create');
    this.route('display', {path: "/display", queryParams: ['filter', 'pageSize', 'page']});
    this.route('edit', { path: '/edit/:user_id' });
    this.route('delete', { path: '/delete/:user_id'});
    this.route('details', { path: '/details/:user_id', queryParams: ['filter', 'pageSize', 'page']});
});...

现在,当用户转到“详细信息”路由时,我会收到user_id并将其保存到localStorage,如下所示:

App.IndexDetailsRoute = Ember.Route.extend({
model: function (params, queryParams) {
    "use strict";
    var ownerId = params.user_id || queryParams.user_id || localStorage.ownerId;
    localStorage.ownerId = ownerId;  //save current userID used later on create product form
    return this.store.find('product', { fields: queryParams });
}, /*just added this code and all start work :) */ serialize : function () { "use strict"; return { user_id : localStorage.ownerId }; }});

接下来在控制器中我想做一些过滤,并在重新加载视图后进行更改:

App.IndexDetailsController = Ember.ArrayController.extend({
content: ["index", "indexDisplay"],
entryNotAllowed: true,
fields : {
    "filter" : null,
    "pageSize" : 10,
    "page" : 0
},
actions: {
    refreshUsersTable : function () {
        "use strict";
        var that = this, call, pageSize, page, filter, ownerId;
        pageSize = this.get("fields.pageSize");
        page = this.get("fields.page");
        filter = this.get("fields.filter");
        ownerId = localStorage.ownerId;
        this.transitionToRoute('index.details', {user_id: ownerId, queryParams : {filter : filter, pageSize: pageSize, page : page}});
    }

}});

问题是,当我调用refreshUsersTable方法时,我在URL中刷新了filter / pageSize / page,但动态段是“未定义的”。

那么,这里有什么问题?请帮助:)

0 个答案:

没有答案