【发布时间】:2015-08-19 19:50:27
【问题描述】:
当我尝试在 Ember 应用程序中访问 URL“/posts”时出现错误。我收到以下错误:
Uncaught Error: More context objects were passed than there are dynamic segments for the route: posts.index
这真是令人费解,因为没有动态的索引段,我的路线是这样的:
Router.map(function() {
this.route('posts', function() {
this.route('new');
this.route('show', {
path: ':post_id'
});
});
});
模型的一部分(models/posts.js):
import DS from 'ember-data';
let Post = DS.Model.extend({
title: DS.attr('string'),
author: DS.attr('string'),
content: DS.attr('string')
});
Post.reopenClass({
FIXTURES: [
{
id: 1,
title: "Random text",
author: "Someone new",
content: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium aspernatur quam qui commodi beatae placeat ducimus aliquam veritatis ullam sed! Sit assumenda aspernatur sunt harum accusamus, repellat labore! Repellendus, corporis!"
}
]
});
export default Post;
我用来访问 /posts 的链接:
{{link-to 'Posts' 'posts'}}
附加信息:我使用的是 ember-cli-cordova,所以我的 environment.js 包含“defaultLocationType: 'auto'”并且我也在使用固定装置,所以我有以下适配器:
export default DS.FixtureAdapter.extend({
host: config.apiUrl
});
有没有人发现任何会导致错误的问题?提前谢谢你。
编辑:
我的发布路线(routes/posts/index.js)如下所示:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('post');
}
});
当我注释掉从商店获取数据的行时,一切正常,所以看起来问题可能与固定装置的使用有关。回家后,我将尝试在 ember jsBin 上创建最小示例。
【问题讨论】:
标签: ember.js