![](/img/trans.png)
[英]EmberJS : “Uncaught Error: More context objects were passed than there are dynamic segments for the route”
[英]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
) :
是指定动态段的重要点。
接受的答案有效。
但是,考虑到示例中op的位置,更正确的解决方法是单独留下以下内容:
this.resource('posts');
并在它下面添加:
this.resource('post', { path: '/post/:post_id'});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.