Ember Router 转换为带参数的嵌套路由

Eve*_*nos 2 ember.js ember-data

App.Router.map(function() {
    this.resource('documents', { path: '/documents' }, function() {
        this.route('edit', { path: ':document_id/edit' });
    });
    this.resource('documentsFiltered', { path: '/documents/:type_id' }, function() {
        this.route('edit', { path: ':document_id/edit' });
        this.route('new');
    });
});
Run Code Online (Sandbox Code Playgroud)

这个控制器带有一个子视图事件,基本上转换为过滤后的文档

App.DocumentsController = Ember.ArrayController.extend({
    subview: function(context) {
    Ember.run.next(this, function() {
        //window.location.hash = '#/documents/'+context.id;
        return this.transitionTo('documentsFiltered', context);
    });
},
});
Run Code Online (Sandbox Code Playgroud)

我的问题是,当页面哈希值更改时,此代码可以正常工作。

但是当我运行上面的代码而不使用 location.hash 位并且使用 Ember 本机时,transitionTo我得到了一个神秘的信息

未捕获的类型错误:对象 [object Object] 没有方法“切片”

有什么线索吗?

谢谢

更新:

App.DocumentsFilteredRoute = Ember.Route.extend({
model: function(params) {
    return App.Document.find({type_id: params.type_id});
},
});

{{#collection contentBinding="documents" tagName="ul" class="content-nav"}}
<li {{action subview this}}>{{this.nameOfType}}</li>
{{/collection}}
Run Code Online (Sandbox Code Playgroud)

mav*_*ein 5

问题是您的模型挂钩返回一个数组,而在您的transitionTo 中您使用的是单个对象。根据经验,对transitionTo 的调用应传递与模型挂钩返回的相同数据结构。遵循这条经验法则,我建议执行以下操作:

App.DocumentsController = Ember.ArrayController.extend({
    subview: function(document) {
        var documents = App.Document.find({type_id: document.get("typeId")});
        Ember.run.next(this, function() {
            return this.transitionTo('documentsFiltered', documents);
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

注意:我假设 type_id 存储在属性 typeId 中。也许您需要根据您的需要进行调整。