不知道这是怎么回事。我在尝试建立新模型的实例时遇到错误。一直在尝试一些不同的解决方案来顺利导出模型。经过数小时的尝试,我决定将我的第一个问题发布在stackoverflow上。
谢谢!
Note_model.js:
const Schema = mongoose.Schema;
const NoteSchema = new Schema({
a_string: String,
a_date: Date
});
module.exports = mongoose.model('Note', NoteSchema);
Article.js
const mongoose = require('mongoose');
import Layout from '../components/Layout'
const Note = require('../models/Note_model');
class Article extends Component {
constructor(props) {
super(props);
this.state = {
value: 'Write new Article.'
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert('An article was submitted: ' + this.state.value);
var awesome_instance = new Note({ a_string: "hey" });
awesome_instance.save(function (err) {
if (err) return handleError(err);
});
}
render() {
return (
<div className="container">
<Layout title="Create Article">
<form onSubmit={this.handleSubmit}>
<label>
Essay:
<textarea value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
</Layout>
</div>
);
}
}
export default Article;
错误消息:
Article.handleSubmit
./pages/Article.js:27
24 |
25 | alert('An article was submitted: ' + this.state.value);
> 26 | var awesome_instance = new Note({ a_string: "hey" });
| ^ 27 |
28 | awesome_instance.save(function (err) {
29 | if (err) return handleError(err);