javascript 未捕获 传递的上下文对象比路由的动态段多:post
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17937433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught More context objects were passed than there are dynamic segments for the route: post
提问by NealR
I'm trying to follow this basic Ember.js tutorialbut having no luck with the "posts" model. I have everything set up according to the demonstration, however I am getting the error:
我正在尝试遵循这个基本的 Ember.js 教程,但对“帖子”模型没有运气。我已经根据演示设置了所有内容,但是出现错误:
Uncaught More context objects were passed than there are dynamic segments for the route: post
Uncaught More context objects were passed than there are dynamic segments for the route: post
Since this is the first time I've ever worked with an Ember.js app, I honestly have no clue what this means. Any help (literally anything) would be greatly appreciated.
由于这是我第一次使用 Ember.js 应用程序,老实说我不知道这意味着什么。任何帮助(字面意思)将不胜感激。
Here is my App.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"
}];
And here is the html for the posts.
这是帖子的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>
回答by AndrewK
I think you meant to have a route specified.
我想你的意思是指定了一条路线。
this.resource('posts', function() {
this.route('post', { path:'/post/:post_id'})
});
The error sounds like you are passing something like post/12
and you don't have a dynamic segment specified(written as :post_id
) The :
is the important point that specifies a dynamic segment.
该错误听起来像您正在传递类似的东西post/12
并且您没有指定动态段(写为:post_id
) 这:
是指定动态段的重要点。
Taken from the Ember.js documentation
回答by Jay
The accepted answer works.
接受的答案有效。
However, given where the op is in the example, the more correct fix is to leave the following alone:
但是,考虑到操作在示例中的位置,更正确的解决方法是不考虑以下内容:
this.resource('posts');
and add this below it:
并在其下方添加:
this.resource('post', { path: '/post/:post_id'});