我使用Loopback 3创建API,我有这样的模型
Section.js

Section.json

输出

我想把start_date减到-7小时,这样就变成这样了。
...
"start_date": "2019-06-23T17:00:00.000Z",
...我尝试使用这个线程How do I create getter and setter overrides?中的getter,如下所示

但一切都没变,我是不是做错了?
发布于 2019-06-24 14:07:09
是的,现在你必须在最后打电话给Section.setup()。这是默认的User模型。
所以基本上,
module.exports = function(User) {
User.setup = function() {
// We need to call the base class's setup method
User.base.setup.call(this);
var UserModel = this;
UserModel.setter.email = function(value) {
if (!UserModel.settings.caseSensitiveEmail) {
this.$email = value.toLowerCase();
} else {
this.$email = value;
}
};
return UserModel;
};
/*!
* Setup the base user.
*/
User.setup();
};我不知道该怎么做,但我做了一个看起来很有效的MCVE (Bug):
module.exports = function(Some) {
Some.setup = function() {
Some.base.setup.call(this);
var UserModel = this;
Some.getter.name = function(){
console.log(this.$name);
return this.$name+"lol";
}
}
Some.setup();
};https://stackoverflow.com/questions/56729466
复制相似问题