首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSDoc +猫鼬:如何记录猫鼬模型?

JSDoc +猫鼬:如何记录猫鼬模型?
EN

Stack Overflow用户
提问于 2016-08-12 10:00:28
回答 2查看 5K关注 0票数 18

我有Mongoose 模式模型

代码语言:javascript
复制
var MyClientSchema = new mongoose.Schema({
    fist_name: {
        type: String
    },
    phone_number: {
        type: String
    }
});

var MyClient = mongoose.model('MyClient', MyClientSchema);

我应该如何文档化(使用MyClient MyClientSchema 和/或MyClientSchema)从 WebStorm获得选项卡-完成和输入来自mongoose.model (如remove, findOne, find )继承的和从模式类phone_number and first_name继承的两种方法的建议?

EN

回答 2

Stack Overflow用户

发布于 2018-07-12 02:27:05

我发现@class (或其同义词@constructor)适用于模式属性:

代码语言:javascript
复制
/**
 * @class MyClient
 */
var MyClientSchema = new mongoose.Schema({
    fist_name: {
        type: String
    },
    phone_number: {
        type: String
    }
});

var MyClient = mongoose.model('MyClient', MyClientSchema);

@alias适用于以旧方式声明的方法:

代码语言:javascript
复制
/**
 * @alias MyClient.prototype.getDescription
 */
MyClientSchema.method('getDescription', function () {
    return this.first_name + " " + this.phone_number;
});

但是,如果使用声明方法的新方法,则可以同时将所有方法标记为MyClient 的一部分

代码语言:javascript
复制
/**
 * @class MyClient
 * @mixes {MyClientSchema.methods}
 */
var MyClientSchema = new mongoose.Schema({ ...

/** @mixin */
MyClientSchema.methods;

MyClientSchema.methods.getDescription = function () {
    return this.first_name + " " + this.phone_number;
};

在最新的WebStorm版本(2018.2)中进行了上述测试。它起作用了。

不起作用的事情:

  • 猫鼬内置的方法,如.find().save()
  • .methods语法突出显示工作,但代码完成不起作用。

欢迎更新!

票数 7
EN

Stack Overflow用户

发布于 2017-04-27 14:41:41

虽然它可能不适合您的特定需求,但官方文档中的jet脑教程解释了您所需要的大部分内容。

https://www.jetbrains.com/help/webstorm/2017.1/creating-jsdoc-comments.html

例如,

代码语言:javascript
复制
/**
 * MyClientSchema schema
 * @constructor MyClient
 */

var MyClientSchema = new mongoose.Schema({
        fist_name: {
            type: String
        },
        phone_number: {
            type: String
        }
    });

下面的js可能是指导您完成几乎所有需要的事情的向导。

http://nagyv.github.io/estisia-wall/models.js.html

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38915195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档