2

我有用于文件上传的 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>
        );
    }
}
4

1 回答 1

1

fsFile = new FS.File(file);行中的问题,您没有声明,let但在此行的下方您再次调用了这个,我希望问题从那里发生,使用如下

let fsFile = new FS.File(file);
ProjectImages.insert(fsFile, function(err, result){
    ....
于 2018-11-23T08:22:30.477 回答