Meteor的todos示例运行良好。但是,当我向Todos和Lists集合添加了一个模式时,我不断得到"错误:列表ID必须是一个对象"。任何帮助将不胜感激。
添加了: meteor add aldeed:simple-schema meteor add aldeed:collection2
这是添加到collections.js文件的新架构:
Lists = new Mongo.Collection('lists');
var Schema = {};
Schema.Lists = new SimpleSchema({
name: {
type: String
},
incompleteCount: {
type: Number
}
});
Lists.attachSchema(Schema.Lists);
Todos = new Mongo.Collection('todos');
Schema.Todos = new SimpleSchema({
listId: {
type: Object
},
text: {
type: String
},
createdAt: {
type: Date
}
});
Todos.attachSchema(Schema.Todos);
没有其他改变。
在我开始流星之前,我做了一次"流星重置"。
尝试将新列表的_id(list_id)附加到Todos架构的listId对象时,bootstrap.js文件中出现以下错误: 。 。 。 {姓名:"最喜欢的科学家", 项目:[" Ada Lovelace", " Grace Hopper", " Marie Curie", " Carl Friedrich Gauss", " Nikola Tesla", "克劳德香农" ] } ];
var timestamp = (new Date()).getTime();
_.each(data, function(list) {
var list_id = Lists.insert({name: list.name,
incompleteCount: list.items.length});
_.each(list.items, function(text) { //line 43
Todos.insert({listId: list_id, //line 44
text: text,
createdAt: new Date(timestamp)});
timestamp += 1; // ensure unique timestamp.
});
});
(STDERR) throw(ex);
(STDERR) ^
(STDERR) Error: List id must be an object
(STDERR) at getErrorObject (meteor://💻app/packages/aldeed_collection2-core/lib/collection2.js:345:1)
(STDERR) at [object Object].doValidate (meteor://💻app/packages/aldeed_collection2-core/lib/collection2.js:328:1)
(STDERR) at [object Object].Mongo.Collection.(anonymous function) [as insert] (meteor://💻app/packages/aldeed_collection2-core/lib/collection2.js:83:1)
(STDERR) at meteor://💻app/server/bootstrap.js:44:1
(STDERR) at Array.forEach (native)
(STDERR) at Function._.each._.forEach (meteor://💻app/packages/underscore/underscore.js:105:1)
(STDERR) at meteor://💻app/server/bootstrap.js:43:1
(STDERR) at Array.forEach (native)
(STDERR) at Function._.each._.forEach (meteor://💻app/packages/underscore/underscore.js:105:1)
(STDERR) at meteor://💻app/server/bootstrap.js:39:1
=> Meteor服务器重启 =>开始使用您的应用。
答案 0 :(得分:0)
class DragAndDrop {
item: Item;
documentBody: HTMLBodyElement;
constructor(documentBody: HTMLBodyElement, item: Item) {
this.documentBody = documentBody;
this.item = item;
this.documentBody.addEventListener("mousedown", this.onmousedown);
}
onmousedown = (event: MouseEvent): void => {
if (CollisionDetector.pointInRect(event.clientX, event.clientY, this.item)) {
// Similarly ...
}
}
}
返回新创建的对象的_id,这是一个字符串,因此list_id变量返回一个字符串并使您的架构无效。将Schema.Todos listId类型更改为String而不是Object。
Lists.insert()