我有Mongoose 模式和模型
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继承的两种方法的建议?
发布于 2018-07-12 02:27:05
我发现@class (或其同义词@constructor)适用于模式属性:
/**
* @class MyClient
*/
var MyClientSchema = new mongoose.Schema({
fist_name: {
type: String
},
phone_number: {
type: String
}
});
var MyClient = mongoose.model('MyClient', MyClientSchema);@alias适用于以旧方式声明的方法:
/**
* @alias MyClient.prototype.getDescription
*/
MyClientSchema.method('getDescription', function () {
return this.first_name + " " + this.phone_number;
});但是,如果使用声明方法的新方法,则可以同时将所有方法标记为MyClient 的一部分:
/**
* @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语法突出显示工作,但代码完成不起作用。欢迎更新!
发布于 2017-04-27 14:41:41
虽然它可能不适合您的特定需求,但官方文档中的jet脑教程解释了您所需要的大部分内容。
https://www.jetbrains.com/help/webstorm/2017.1/creating-jsdoc-comments.html
例如,
/**
* 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
https://stackoverflow.com/questions/38915195
复制相似问题