例如,如果我有这段代码(posts.js
)
var mongoose = require('mongoose');
var postsSchema = mongoose.Schema({
_id: Number,
title: String,
description: String,
comments: [{ type: String, minlength: 1, required: true }]
});
var Post = mongoose.model('Posts', postsSchema);
module.exports = Post;
并将在某处使用此模型,例如:
var Post = require('../models/posts');
Post.{strg+space}
它可以工作,但我不能使用代码完成,如果我调用一个函数,我会在IntelliJ编辑器中看到“未解析函数”的错误。
如果我将导出更改为:
module.exports = {Post:Post};
或
exports.Post = Post;
并导入模型:
var Post = require('../models/posts').Post;
一切似乎都很好。
这是一个错误还是我做错了什么?
答案 0 :(得分:0)
The IDE does not maintain the symbols from user written js files by default. You need to add them explicitly to a project for them to be available in the code completion.
You can add a file or a library by going to Settings -> Language & Frameworks -> Javascript -> Libraries.
Then click on Add and add your file using the + button. It gives you an options to even add an entire directory.
答案 1 :(得分:0)
这是一个已知问题,请关注WEB-17099了解更新