gpt4 book ai didi

node.js - 如何在 sails.js 中保存模型?

转载 作者:太空宇宙 更新时间:2023-11-03 23:34:14 25 4
gpt4 key购买 nike

如何将此模型项目保存在 sails.js 中

 module.exports = {
attributes: {
name : {
en: {type: String},
fr: {type: String},
it: {type: String},
es: {type: String}
}
}
};

我尝试这样做在 Controller 中

 module.exports = {       
addItem: function(req, res) {
var params = {
en : req.body.en,
fr : req.body.fr,
it : req.body.it,
es : req.body.es
};

Items.addItem(params, function(success) {
res.json(success);
});
}
};

之后我调用了一项服务

 module.exports = {
addItem: function(params, next) {
Items.create({value: params}).exec(function(err, item) {
if(err) throw err;
next(item);
});
}
};

但是当我尝试发布对象时出现以下错误未知规则:en如何解决这个问题?谢谢

最佳答案

您在这里尝试做的是嵌入子文档,问题是 sails Waterline 尚不支持嵌入,目前您可以在 git-hub here 上查看此问题的状态因为 sails 团队已将此纳入其功能请求中,并且可能会在即将推出的版本中引入。

如果您仍然想存储它,请不要在模型中声明它,它最终会被保存,但不建议这样做。

您也可以将其存储为数组,我想这会有所帮助。

查看#sails-mongo:How can I validate a Sub-document? git-hub

关于node.js - 如何在 sails.js 中保存模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34557525/

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