0

我在这里有点束缚。代码应该是正确的,但 Chrome 一直说第 27 行有一个未捕获的类型引用。

它无法读取 null 的属性“名称”。我已经检查了这段代码大约三遍,但找不到它给我带来问题的原因。

希望另一双眼睛能看一看。

var React = require("react");
var actions = require("../actions/SchoolActions");

module.exports = React.createClass({
    getInitialState: function () {
        return {
            name: "",
            tagline: "",
        };
    },
    addSchool: function (e) {
        e.preventDefault();
        actions.addSchool(this.state);
    },
    handleInputChange: function (e) {
        e.preventDefault();
        var name = e.target.name;
        var state = this.state;
        state[name] = e.target.value;
        this.setState(state);
    },
    render: function () {
        return (
            <form className="form" onSubmit={this.addSchool}>
                <div className="form-group">
                    <label className="control-label" htmlFor="name">
                        School Name:
                    </label>
                    <input
                        type="text"
                        className="form-control"
                        id="name"
                        name="name"
                        value={this.state.name}
                        onChange={this.handleInputChange}
                        placeholder="School Name"
                    />
                </div>
                <div className="form-group">
                    <label className="control-label" htmlFor="tagline">
                        Tagline:
                    </label>
                    <input
                        type="text"
                        className="form-control"
                        id="tagline"
                        name="tagline"
                        value={this.state.address}
                        onChange={this.handleInputChange}
                        placeholder="Tagline"
                    />
                </div>
                <div className="form-group">
                    <button className="btn" type="submit">
                        Add School
                    </button>
                </div>
            </form>
        );
    },
});

4

0 回答 0