简体   繁体   English

EmberJS:“未捕获错误:传递了更多上下文对象,而不是路径的动态段”

[英]EmberJS : “Uncaught Error: More context objects were passed than there are dynamic segments for the route”

I have two routes of which one of them uses a dynamic segment : 我有两条路线,其中一条路线使用动态线段:

App.Router.map(function() {
    this.resource('books');
    this.resource('book', {
        path: "/book/:book_uid"
    })
});

When i try the helper {{link-to 'book' abook.uid}} in the Books template, I get the error : 当我在Books模板中尝试帮助{{link-to'book'abook.uid}}时,我收到错误:

Uncaught Error: More context objects were passed than there are dynamic segments for the route: book 未捕获的错误:传递的上下文对象多于路径:book的动态段

This is the model for Book : 这是Book的模型:

App.Book = DS.Model.extend({
    book_id: DS.attr()      
});

and this is how i define the route for Book : 这就是我为Book定义路线的方式:

 App.BookRoute = Ember.Route.extend({
            model: function(params) {
                return this.store.find('book', params.book_uid);
            },
            serialize: function(model) {
                return {
                    book_uid: model.get('uid')
                };
            } 
});

Any ember saints out there who can give a look see??? 任何灰烬圣徒在那里谁可以看看???

When the link-to helper is used in inline form the first parameter is used as the link text and the remaining args as your route path. link-to帮助器以内联形式使用时,第一个参数用作链接文本,剩余的args用作路径路径。

So you in your case you have to pass three args to it like this: 所以你在你的情况下你必须像这样传递三个args:

{{link-to 'Show book' 'book' abook.uid}}

Or use the block form in this way: 或者以这种方式使用块形式:

{{#link-to 'book' abook.uid}}
  Show book
{{/link-to}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM