我为什么得到表格没有定义?

时间:2017-01-27 04:53:52

标签: javascript reactjs

我正在尝试开发一个锻炼应用程序,现在我只是想测试一个按钮,当我点击它时,它会添加短语'这是表格',但我的浏览器已空白并在控制台中我收到此错误:

未捕获的ReferenceError:表单未定义

这是我的components / app.js文件:

import React from 'react';
import AppActions from '../actions/AppActions';
import AddForm from './AddForm.js';

export default class App extends React.Component {

    render(){

        return(
            <div>
                <h1 className="text-center page-header">WorkoutLogger</h1>
                <a onClick={AppActions.showForm.bind(null, 'this is the form')} href="#" className="btn btn-primary btn-block">Add Workout</a>
                <br />
                {form}
                <br />
                WORKOUTS
                <br />
            </div>
        );
    }
}

这是我的components / AddForm.js文件:

import React from 'react';

export default class AddForm extends React.Component {

    render(){
        return(
            <div>
                FORM
            </div>
        );
    }
}

这是我的行动/ AppActions.js文件:

import {dispatch, register} from '../dispatcher/AppDispatcher';
import AppConstants from '../constants/AppConstants';

export default {
    showForm(form){
        dispatch({
            actionType: AppConstants.SHOW_FORM, form
        })
    }
}

这是我的调度程序/ AppDispatcher.js文件:

import {Dispatcher} from 'flux';

const flux = new Dispatcher();

export function register(callback) {
    return flux.register(callback);
}

export function dispatch(payload){
    console.log(payload)
    flux.dispatch(payload);
}

这是我的常量/ AppConstants.js文件:

export default {
    SHOW_FORM: 'SHOW_FORM'
}

这是我的商店/ AppStore.js文件:

import {dispatch, register} from '../dispatcher/AppDispatcher';
import AppConstants from '../constants/AppConstants';
import {EventEmitter} from 'events';
import assign from 'object-assign';
import AppAPI from '../utils/AppAPI';

const CHANGE_EVENT = 'change';
const _showForm = false;

var _items = [];

var AppStore = assign({}, EventEmitter.prototype, {
    emitChange: function(){
        this.emit(CHANGE_EVENT);
    },
    showForm: function(){
        _showForm = true;
    }
})

AppDispatcher.register(function(payload){
    var action = payload.action;

    switch(action.actionType){
        case AppConstants.SHOW_FORM:
            AppStore.showForm();
            AppStore.emit(CHANGE_EVENT);
            break;
    }

    return true;
});

module.exports = AppStore;

1 个答案:

答案 0 :(得分:0)

{form}未在您的components / app.js中定义,如果您想在该位置显示AddForm组件,请将