Ember.js 您需要将型号名称传递给商店';方法的s模型
我有很多关于工作关系的问题 当我试图列出文章的评论时,我有Ember.js 您需要将型号名称传递给商店';方法的s模型,ember.js,ember-data,Ember.js,Ember Data,我有很多关于工作关系的问题 当我试图列出文章的评论时,我有articles/show视图,但我一直收到标题中指出的错误 它与belongsTo有关:DS.belongsTo('article'),但我不知道它是什么 这是我的文件。 路线/文章/show.js 控制器/articles/show.js 模板/文章/show.hbs serializers/comment.js import DS from 'ember-data'; const { belongsTo, attr } = DS;
articles/show
视图,但我一直收到标题中指出的错误
它与belongsTo有关:DS.belongsTo('article')
,但我不知道它是什么
这是我的文件。
路线/文章/show.js
控制器/articles/show.js
模板/文章/show.hbs
serializers/comment.js
import DS from 'ember-data';
const { belongsTo, attr } = DS;
export default DS.Model.extend({
article: belongsTo(),
user: belongsTo(),
body: attr('string')
});
序列化程序/article.js
import DS from 'ember-data';
import Ember from 'ember';
const { attr, hasMany } = DS;
const { computed: { gt } } = Ember;
export default DS.Model.extend({
title: attr('string'),
content: attr('string'),
authorName: attr('string'),
authorAvatar: attr('string'),
authorUrl: attr('string'),
comments: hasMany('comment', {async: true}),
hasAvatar: gt('authorAvatar.length', 0)
});
从“余烬数据”导入DS
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
comments: { embedded: 'always' }
}
});
models/article.js
import DS from 'ember-data';
import Ember from 'ember';
const { attr, hasMany } = DS;
const { computed: { gt } } = Ember;
export default DS.Model.extend({
title: attr('string'),
content: attr('string'),
authorName: attr('string'),
authorAvatar: attr('string'),
authorUrl: attr('string'),
comments: hasMany('comment', {async: true}),
hasAvatar: gt('authorAvatar.length', 0)
});
编辑:
ember.debug.js:16905 Assertion Failed: You need to pass a model name to the store's modelFor method
Error
at assert (http://ffl.com:8000/assets/vendor.js:16268:13)
at Object.assert (http://ffl.com:8000/assets/vendor.js:27196:34)
at assert (http://ffl.com:8000/assets/vendor.js:135212:37)
at Class.modelFor (http://ffl.com:8000/assets/vendor.js:145201:41)
at Class._internalModelForId (http://ffl.com:8000/assets/vendor.js:144337:29)
at Class._pushResourceIdentifier (http://ffl.com:8000/assets/vendor.js:145716:19)
at BelongsToRelationship.updateData (http://ffl.com:8000/assets/vendor.js:142394:36)
at BelongsToRelationship.push (http://ffl.com:8000/assets/vendor.js:142976:14)
at http://ffl.com:8000/assets/vendor.js:145795:20
at http://ffl.com:8000/assets/vendor.js:141943:18
defaultDispatch @ ember.debug.js:16905
dispatchError @ ember.debug.js:16888
onerrorDefault @ ember.debug.js:30389
trigger @ ember.debug.js:57833
(anonymous) @ ember.debug.js:58717
invoke @ ember.debug.js:339
flush @ ember.debug.js:407
flush @ ember.debug.js:531
end @ ember.debug.js:601
run @ ember.debug.js:724
join @ ember.debug.js:746
run.join @ ember.debug.js:21556
hash.success @ rest.js:954
fire @ jquery.js:3305
fireWith @ jquery.js:3435
done @ jquery.js:9242
(anonymous) @ jquery.js:9484
我在这里按照注释中的要求添加了注释模型代码
models/comment.js
import DS from 'ember-data';
const { belongsTo, attr } = DS;
export default DS.Model.extend({
article: belongsTo(),
user: belongsTo(),
body: attr('string')
});
这是来自检查员的stacktrace:
ember.debug.js:16905 Assertion Failed: You need to pass a model name to the store's modelFor method
Error
at assert (http://ffl.com:8000/assets/vendor.js:16268:13)
at Object.assert (http://ffl.com:8000/assets/vendor.js:27196:34)
at assert (http://ffl.com:8000/assets/vendor.js:135212:37)
at Class.modelFor (http://ffl.com:8000/assets/vendor.js:145201:41)
at Class._internalModelForId (http://ffl.com:8000/assets/vendor.js:144337:29)
at Class._pushResourceIdentifier (http://ffl.com:8000/assets/vendor.js:145716:19)
at BelongsToRelationship.updateData (http://ffl.com:8000/assets/vendor.js:142394:36)
at BelongsToRelationship.push (http://ffl.com:8000/assets/vendor.js:142976:14)
at http://ffl.com:8000/assets/vendor.js:145795:20
at http://ffl.com:8000/assets/vendor.js:141943:18
defaultDispatch @ ember.debug.js:16905
dispatchError @ ember.debug.js:16888
onerrorDefault @ ember.debug.js:30389
trigger @ ember.debug.js:57833
(anonymous) @ ember.debug.js:58717
invoke @ ember.debug.js:339
flush @ ember.debug.js:407
flush @ ember.debug.js:531
end @ ember.debug.js:601
run @ ember.debug.js:724
join @ ember.debug.js:746
run.join @ ember.debug.js:21556
hash.success @ rest.js:954
fire @ jquery.js:3305
fireWith @ jquery.js:3435
done @ jquery.js:9242
(anonymous) @ jquery.js:9484
我克隆了您的项目分支重构和升级余烬,但海市蜃楼还没有完成。所以我看了一下代码
headTags() {
let article = this.modelFor(this.routeName);
}
这是routes文章中显示的,您可以尝试删除它并重试。我检查了您的发行和回购。问题只在于Ember.js中的注释序列化程序。应该是:
import DS from 'ember-data';
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
article: { embedded: 'always' },
user: { embedded: 'always' }
}
});
您是否有代码,它调用带有空参数的
modelFor
方法?。您是否定义了注释模型?。如果是这样的话,也把它贴出来?。如果可能,为该断言错误插入堆栈跟踪。确定触发modelFor
的方法。最新版本的find
是私有方法。@kumkanillam我根据您的要求添加了这两个方法。希望这会有所帮助。我们不需要在belongsTo关系中提到模型名称吗,比如注释模型的article:belongsTo('article')
和user:belongsTo('user
)`。我对此不确定。如果它对您没有帮助,那么您可能需要遍历服务器响应数据格式。我以前确实提到过它(没有更改),但如果名称与关系匹配,则不需要这样做。我没有在整个代码中调用modelFor
。顺便说一句:我在这里你可以查看这个项目的全部源代码。这是最基本的。事实上,即使删除了该选项,也会出现此错误-当我准备问题时,我确实删除了这些标记-这就是为什么我在上面的评论中提到,我没有modelFor
-但我感谢您的努力,谢谢!
headTags() {
let article = this.modelFor(this.routeName);
}
import DS from 'ember-data';
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
article: { embedded: 'always' },
user: { embedded: 'always' }
}
});