【发布时间】:2018-04-23 12:26:54
【问题描述】:
我有一个 MongoDB 服务器,它有一个 NodeJS 服务器与之交互。我希望 Ember Store 从此服务器获取数据。一个教程引导我直到这一点,但它对我不起作用(tutorial),我认为它已经过时但我不确定。 后端服务器这部分是关于发送数据的:
app.get('/api/appointments', function(req, res){
AppointmentModel.find({}, function(err, docs){
if(err) res.send({error:err});
else res.send({data:docs, "type":"appointment"});
});
});
一个 curl 请求证明它确实有效:
curl http://localhost:4500/api/appointments
{"data":[{"flags":[],"dates":[],"invited":[],"_id":"5adc8b6724a69f4327c4c7af","author":7,"title":"Does this work"}],"type":"appointment"}
这是向服务器发出请求的 ember 代码部分:
export default Route.extend({
model: function(){
return this.store.findAll('appointment');
}
});
这是我在 webbrowser(chrome) 的控制台中遇到的错误:
Error while processing route: index Assertion Failed: Encountered a resource object with an undefined type (resolved resource using (unknown mixin)) Error: Assertion Failed: Encountered a resource object with an undefined type (resolved resource using (unknown mixin))
at new EmberError (http://localhost:4200/assets/vendor.js:24475:25)
at Object.assert (http://localhost:4200/assets/vendor.js:24725:15)
at Class._normalizeResourceHelper (http://localhost:4200/assets/vendor.js:85052:61)
at Class._normalizeDocumentHelper (http://localhost:4200/assets/vendor.js:84993:25)
at Class._normalizeResponse (http://localhost:4200/assets/vendor.js:85121:36)
at Class.normalizeArrayResponse (http://localhost:4200/assets/vendor.js:86013:19)
at Class.normalizeFindAllResponse (http://localhost:4200/assets/vendor.js:85873:19)
at Class.normalizeResponse (http://localhost:4200/assets/vendor.js:85816:23)
at normalizeResponseHelper (http://localhost:4200/assets/vendor.js:76037:39)
at promise.then.adapterPayload (http://localhost:4200/assets/vendor.js:76889:19)
因为错误与类型有关,所以我检查并再次检查了模型,但没有发现任何会出错的东西。 余烬:
export default DS.Model.extend({
author: DS.attr('number'),
title: DS.attr('string'),
description: DS.attr('string'),
flags: DS.hasMany('number'),
dates: DS.hasMany('date'),
invited: DS.hasMany('number')
});
NodeJS/Mongo:
//The schema for appointments
var appointmentSchema = new mongoose.Schema({
author: Number, //Userid of the owner of the appointment.
title: String,
description: String,
flags: [Number], //Array of ids of flags that are set.
dates: [Date],
invited: [Number] //Array of user ids.
});
var AppointmentModel = mongoose.model('appointment', appointmentSchema);
ember 需要以什么特殊方式处理数据?
我已经阅读了一些关于 store 和 ember 的文档,但我对框架还是新手,非常感谢任何帮助。
【问题讨论】:
-
调试提示:“return this.store.findAll('appointment');”而不是这个尝试“返回{“作者”:“约翰”}”。您可以尝试各种 JSON 进行调试。
标签: node.js mongodb ember.js ember-data