簡體   English   中英

未捕獲更多上下文對象,而不是路徑的動態段:post

[英]Uncaught More context objects were passed than there are dynamic segments for the route: post

我正在嘗試按照這個基本的Ember.js教程,但沒有運氣的“帖子”模型。 我根據演示設置了所有內容,但是我收到錯誤:

Uncaught More context objects were passed than there are dynamic segments for the route: post

由於這是我第一次使用Ember.js應用程序,所以老實說我不知道​​這意味着什么。 任何幫助(字面上的任何東西)將不勝感激。

這是我的App.js

App = Ember.Application.create();

App.Store = DS.Store.extend({
    adapter: 'DS.FixtureAdapter'
});

App.Router.map(function () {
    this.resource('posts', function() {
        this.resource('post', { path:'post_id'})
    });
    this.resource('about');
});

App.PostsRoute = Ember.Route.extend({
    model: function () {
        return App.Post.find();
    }
})

App.Post = DS.Model.extend({
    title: DS.attr('string'),
    author: DS.attr('string'),
    intro: DS.attr('string'),
    extended: DS.attr('string'),
    publishedAt: DS.attr('date')
});

App.Post.FIXTURES = [{
        id: 1,
        title: "Rails in Omakase",
        author: "d2h",
        publishedAt: new Date('12-27-2012'),
        intro: "Blah blah blah blah",
        extended: "I have no clue what extended means"
    }, {
        id: 2,
        title: "Second post",
        author: "second author",
        publishedAt: new Date('1-27-2012'),
        intro: "second intro",
        extended: "Second extended"
    }];

這是帖子的html。

<script type="text/x-handlebars" id="posts">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span3">
                <table class='table'>
                <thead>
                    <tr><th>Recent Posts</th></tr>
                </thead>
                {{#each model}}
                <tr><td>
                    {{#linkTo 'post' this}}{{title}} <small class='muted'>by {{author}}</small>{{/linkTo}}
                </td></tr>
                {{/each}}
                </table>
            </div>
            <div class="span9">
                {{outlet}}
            </div>
        </div>
    </div>
</script>
<script type="text/x-handlebars" id="post">
    <h1>{{title}}</h1>
    <h2> by {{author}} <small class="muted">{{publishedAt}}</small></h2>

    <hr>

    <div class="intro">
        {{intro}}
    </div>

    <div class="below-the-fold">
        {{extended}}
    </div>
</script>

我認為你的意思是指定一條路線。

this.resource('posts', function() {
    this.route('post', { path:'/post/:post_id'})
});

這個錯誤聽起來像是你傳遞的東西像post/12而你沒有指定動態段(寫成:post_id:是指定動態段的重要點。

取自Ember.js文檔

接受的答案有效。

但是,考慮到示例中op的位置,更正確的解決方法是單獨留下以下內容:

this.resource('posts');

並在它下面添加:

this.resource('post', { path: '/post/:post_id'});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM