I have Mongoose
schema and a model:
我有Mongoose架构和模型:
var MyClientSchema = new mongoose.Schema({
fist_name: {
type: String
},
phone_number: {
type: String
}
});
var MyClient = mongoose.model('MyClient', MyClientSchema);
How should I document (using JSDoc) MyClient
and/or MyClientSchema
to get tab-completion and type suggestions from WebStorm
for both methods inherited from mongoose.model
like remove, findOne, find
- and inherited from schema - like phone_number and first_name
?
我应该如何记录(使用JSDoc)MyClient和/或MyClientSchema来获取tab-completion并从WebStorm输入从mongoose.model继承的方法的建议,例如remove,findOne,find - 并从schema继承 - 如phone_number和first_name?
2 个解决方案
#1
1
I found @class
(or its synonym @constructor
) works for schema properties:
我发现@class(或其同义词@constructor)适用于架构属性:
/**
* @class MyClient
*/
var MyClientSchema = new mongoose.Schema({
fist_name: {
type: String
},
phone_number: {
type: String
}
});
var MyClient = mongoose.model('MyClient', MyClientSchema);
The @alias
works for methods declared the old way:
@alias适用于以旧方式声明的方法:
/**
* @alias MyClient.prototype.getDescription
*/
MyClientSchema.method('getDescription', function () {
return this.first_name + " " + this.phone_number;
});
However, you can mark all methods as part of MyClient
at once if you use the new way of declaring methods:
但是,如果使用新方法声明方法,则可以立即将所有方法标记为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;
};
All the above tested in latest WebStorm version (2018.2). It works.
以上所有测试均采用最新的WebStorm版本(2018.2)。有用。
Things which do not work:
不起作用的事情:
- Mongoose built-in methods like
.find()
or.save()
- Mongoose内置方法,如.find()或.save()
- The
.methods
syntax highlight works but code completion doesn't. - .methods语法突出显示有效,但代码完成没有。
Updates are welcome!
欢迎更新!
#2
0
Although it might not fit your specific requirement, this jet brains tutorial in the official documentation explains most of what you need
虽然它可能不符合您的特定要求,但官方文档中的喷气机大脑教程解释了您需要的大部分内容
https://www.jetbrains.com/help/webstorm/2017.1/creating-jsdoc-comments.html
https://www.jetbrains.com/help/webstorm/2017.1/creating-jsdoc-comments.html
for example,
例如,
/**
* MyClientSchema schema
* @constructor MyClient
*/
var MyClientSchema = new mongoose.Schema({
fist_name: {
type: String
},
phone_number: {
type: String
}
});
and the following js might be a guide foe you to do almost everything you need
以下js可能是你几乎所有需要的指南
http://nagyv.github.io/estisia-wall/models.js.html
http://nagyv.github.io/estisia-wall/models.js.html
#1
1
I found @class
(or its synonym @constructor
) works for schema properties:
我发现@class(或其同义词@constructor)适用于架构属性:
/**
* @class MyClient
*/
var MyClientSchema = new mongoose.Schema({
fist_name: {
type: String
},
phone_number: {
type: String
}
});
var MyClient = mongoose.model('MyClient', MyClientSchema);
The @alias
works for methods declared the old way:
@alias适用于以旧方式声明的方法:
/**
* @alias MyClient.prototype.getDescription
*/
MyClientSchema.method('getDescription', function () {
return this.first_name + " " + this.phone_number;
});
However, you can mark all methods as part of MyClient
at once if you use the new way of declaring methods:
但是,如果使用新方法声明方法,则可以立即将所有方法标记为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;
};
All the above tested in latest WebStorm version (2018.2). It works.
以上所有测试均采用最新的WebStorm版本(2018.2)。有用。
Things which do not work:
不起作用的事情:
- Mongoose built-in methods like
.find()
or.save()
- Mongoose内置方法,如.find()或.save()
- The
.methods
syntax highlight works but code completion doesn't. - .methods语法突出显示有效,但代码完成没有。
Updates are welcome!
欢迎更新!
#2
0
Although it might not fit your specific requirement, this jet brains tutorial in the official documentation explains most of what you need
虽然它可能不符合您的特定要求,但官方文档中的喷气机大脑教程解释了您需要的大部分内容
https://www.jetbrains.com/help/webstorm/2017.1/creating-jsdoc-comments.html
https://www.jetbrains.com/help/webstorm/2017.1/creating-jsdoc-comments.html
for example,
例如,
/**
* MyClientSchema schema
* @constructor MyClient
*/
var MyClientSchema = new mongoose.Schema({
fist_name: {
type: String
},
phone_number: {
type: String
}
});
and the following js might be a guide foe you to do almost everything you need
以下js可能是你几乎所有需要的指南
http://nagyv.github.io/estisia-wall/models.js.html
http://nagyv.github.io/estisia-wall/models.js.html