我正在尝试将流星收集挂钩集成到我的项目中。我安装了它:
meteor add matb33:collection-hooks
并将其添加到tsconfig.json:
"types": [
"meteor-typings",
"@types/underscore",
"@types/meteor-collection-hooks"
]
在package.json中具有依存关系:
"@types/meteor-collection-hooks": "^0.8.3",
在问题/collection.ts中的两个/集合中都有我有方法“ Problems.before.insert”-带下划线的“ before”显示了我在标题中写的错误。 (此方法从最后插入的对象获取problemId,对其进行增加,然后将增加的ID插入新的创建对象中)。问题.collection.ts中的代码:
import { MongoObservable } from "meteor-rxjs";
import { Problem } from "../models/problem.model";
export const Problems = new MongoObservable.Collection<Problem>("problems");
function loggedIn() {
return !!Meteor.user();
}
Problems.allow({
insert: loggedIn,
update: loggedIn,
remove: loggedIn
});
Problems.before.insert(function (problemId, problem) {
let lastProblem = Problems.find({}, { sort: { _id: -1 }, limit: 1 }).fetch()[0];
let lastProblemId = lastProblem.problemSecondId++;
problem.problemSecondId = lastProblemId;
});
我不知道,我做错了什么。好像没有安装该软件包...?