gpt4 book ai didi

javascript - meteor MDG :validated-method without using simple schema

转载 作者:行者123 更新时间:2023-12-03 06:13:00 24 4
gpt4 key购买 nike

嗯,

Simple Schema is in the middle of transitioning to a new version 2.0

同时,我不太确定是否想在我的项目中使用它。

我正在编写一个基于 ES6 React 的 Meteor 应用程序,因此我想利用 The "Advanced" way to create meteor methods 。但是,我根本不想使用 aldeed:simple-schema。

有没有办法在这里放入自定义验证方法?

这不起作用:

export const addSuggestion = new ValidatedMethod({
name: 'suggestion.add',
validate() {
return true
},
run(incommingSuggestion) {
// do things which are not relevant to this question.
}
})

它会产生以下错误:

Error: Returning from validate doesn't do anything; perhaps you meant to throw an error?(…)

有不同的写法吗?

Perhaps I need to not use this validated-method, instead I should maybe write it out long-form? Edit: Edit: This works, you can write everything out long-form with all of this extra boiler plate if you want to avoid validation all together for the time being. For now this is the solution I will use until I finally decide on how I will be validating everything. I'm not sure what to do right now because Simple Schema is in transition. - Actually that doesn't work, it for some reason never returns a value and I couldn't get around that.

有人知道如何解决这个问题吗?

显然谷歌搜索没有找到任何结果,我已经研究这个问题三天多了。

最佳答案

您可以重新实现 SimpleSchema 的 API,但为什么呢?

SimpleSchema 是 Meteor 中事实上的标准,就像 Node<->MongoDB 的 Mongoose 一样。工作中还有其他选择,但我认为您正在插入前沿。

如果您有工作要做,请使用 SimpleSchema。

关于javascript - meteor MDG :validated-method without using simple schema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39236313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com