我在创建/更新环回数据时尝试更改某些字段。 POST方法有效,但现在PUT方法已关闭。
我的category.json:
{
"name": "category",
"base": "PersistedModel",
"properties": {
"name": {
"type": "string",
"required": true
},
"image": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
和用于定义方法的category.js:
module.exports = function(categorie) {
categorie.observe('before save', function(ctx, next){
ctx.instance.name = ctx.instance.name.toUpperCase().trim();
ctx.instance.image = ctx.instance.image.trim();
ctx.instance.image = ctx.instance.image.charAt(0).toUpperCase() + ctx.instance.image.slice(1);
next();
});
};
我收到此错误消息:
{ "错误":{ " name":" TypeError", "状态":500, "消息":"无法读取属性' name'未定义", " stack":" TypeError:无法读取属性' name'未定义的\ n在/home/pitt/warm-wildwood-2324/common/models/category.js:5:35,n at notifySingleObserver(/ home / pitt / warm-wildwood-2324 / node_modules / loopback-datasource-juggler /lib/model.js:600:22)\n( ...)在Function.ModelBaseClass.notifyObserversOf(/home/pitt/warm-wildwood-2324/node_modules/loopback-datasource-juggler/lib/model.js: 593:8)" } }