【发布时间】:2015-03-19 16:13:29
【问题描述】:
当我使用环回创建/更新数据时,我尝试更改某些字段。 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();
});
};
我收到此错误消息:
{ “错误”: { “名称”:“类型错误”, “状态”:500, "message": "无法读取未定义的属性 'name'", "stack": "TypeError: Cannot read property 'name' of undefined\n at /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)" } }
【问题讨论】:
标签: post put loopbackjs