javascript - 未捕获 传递的上下文对象多于路由的动态段 : post

标签 javascript ember.js handlebars.js

我正在尝试关注this basic Ember.js tutorial但对“帖子”模型没有运气。我已根据演示设置了所有内容,但是我收到错误:

未捕获 传递的上下文对象多于路由的动态段: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 documentation

关于javascript - 未捕获 传递的上下文对象多于路由的动态段 : post,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17937433/

相关文章:

javascript - 在按钮的 ng-click 上绑定(bind) Angular 中的 Kendo 网格

javascript - 如何在 javascript 中将子数组字符串数组转换为子数组数组?

ember.js - 如何从 Ember 数据存储中删除所有数据?

ember.js - Ember - 在路线上绑定(bind)自定义操作

javascript - console.log 或 utils.inspect 的隐藏属性

javascript - 使用 JavaScript AJAX 脚本可以完成多少网络故障排除?

ember.js - Ember-cli 插件和助手

javascript - Uncaught Error : Nothing handled the action 'createTodo'

javascript - handle - 无法循环数据

node.js - Express + Handlebars 上的 Socket.io 无法在 https 上运行