Sails js custom/calculated 属性不起作用,使用来自 sails 文档的代码

Sails js custom/calculated attributes is not working, using code from sails docs

我有这个模型取自 sails documentation page

module.exports = {

    attributes: {
    // Primitive attributes
    firstName: {
      type: 'string',
      defaultsTo: ''
    },
    lastName: {
      type: 'string',
      defaultsTo: ''
    },

    // Attribute methods
    getFullName: function (){
      return this.firstName + ' ' + this.lastName;
    }
  }
};

当我调用自动生成的 restful api(使用蓝图)时我期望什么

localhost:port/resourceName

{"firstName":"john", "lastName":"Doe", "getFullName": "john Doe"}

我得到的是这个

{"firstName":"john", "lastName":"Doe"}

有什么想法吗?

我已经检查过其他帖子,比如这个github

帆版本:0.11.4

非常感谢:)

如果您希望自定义属性被序列化,您可以覆盖默认的 toJSON 实例方法:

toJSON: function() {
  var obj = this.toObject();
  obj.fullName = this.getFullName();
  return obj;
}