cfs 集合在 react.component 中显示错误
cfs collection showing error in react.component
我有用于文件上传的 cfs 集合。我已经在模板中使用过它并且效果很好。现在我必须使用此 react.component 但它显示此错误 Uncaught ReferenceError: fsFile is not defined
。我添加了 FS.Collection 但它仍然显示错误。它在我使用模板但不在反应组件中工作时工作。我该如何解决这个问题?
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import React from 'react';
import Switch from 'react-switch';
import {Events} from './../../api/events';
import DatePicker from "react-datepicker";
import moment from "moment";
import "react-datepicker/dist/react-datepicker.css";
export default class AddEvent extends React.Component{
EventForm(e){
e.preventDefault();
let eventTitle = e.target.title.value;
let file = $('#projectImage').get(0).files[0];
if(file){
fsFile = new FS.File(file);
ProjectImages.insert(fsFile, function(err, result){
if(!err){
var projectImage = '/cfs/files/ProjectImages/' + result._id;
// Insert Project
Events.insert({
name: eventTitle,
projectImage: projectImage
});
}
});
} else {
// Insert Project
Events.insert({
name: eventTitle
});
}
}
render(){
return(
<div className="tab-pane fade" id="upEvents">
<form className="upload-event-from" onSubmit={this.EventForm.bind(this)}>
<div className="form-group">
<input type="text" className="form-control" id="event_title" placeholder="Event Title" name="title" />
<span className="error-message eventTitle"></span>
</div>
<div className="form-group fg-icon">
<label>Upload Image</label>
<input type="file" className="form-control" name="projectImage" id="projectImage" />
<img id="blah" src="#" alt="your image" />
</div>
<center>
<button type="submit" className="btn app-btn">Publish</button>
</center>
</form>
</div>
);
}
}
fsFile = new FS.File(file);
行中的问题,您没有声明 let
但在此行下方您再次调用了它,我希望问题从那里发生,使用如下
let fsFile = new FS.File(file);
ProjectImages.insert(fsFile, function(err, result){
....
我有用于文件上传的 cfs 集合。我已经在模板中使用过它并且效果很好。现在我必须使用此 react.component 但它显示此错误 Uncaught ReferenceError: fsFile is not defined
。我添加了 FS.Collection 但它仍然显示错误。它在我使用模板但不在反应组件中工作时工作。我该如何解决这个问题?
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import React from 'react';
import Switch from 'react-switch';
import {Events} from './../../api/events';
import DatePicker from "react-datepicker";
import moment from "moment";
import "react-datepicker/dist/react-datepicker.css";
export default class AddEvent extends React.Component{
EventForm(e){
e.preventDefault();
let eventTitle = e.target.title.value;
let file = $('#projectImage').get(0).files[0];
if(file){
fsFile = new FS.File(file);
ProjectImages.insert(fsFile, function(err, result){
if(!err){
var projectImage = '/cfs/files/ProjectImages/' + result._id;
// Insert Project
Events.insert({
name: eventTitle,
projectImage: projectImage
});
}
});
} else {
// Insert Project
Events.insert({
name: eventTitle
});
}
}
render(){
return(
<div className="tab-pane fade" id="upEvents">
<form className="upload-event-from" onSubmit={this.EventForm.bind(this)}>
<div className="form-group">
<input type="text" className="form-control" id="event_title" placeholder="Event Title" name="title" />
<span className="error-message eventTitle"></span>
</div>
<div className="form-group fg-icon">
<label>Upload Image</label>
<input type="file" className="form-control" name="projectImage" id="projectImage" />
<img id="blah" src="#" alt="your image" />
</div>
<center>
<button type="submit" className="btn app-btn">Publish</button>
</center>
</form>
</div>
);
}
}
fsFile = new FS.File(file);
行中的问题,您没有声明 let
但在此行下方您再次调用了它,我希望问题从那里发生,使用如下
let fsFile = new FS.File(file);
ProjectImages.insert(fsFile, function(err, result){
....