Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法读取带有linkedState的reactJs中的null值_Javascript_Reactjs - Fatal编程技术网

Javascript 无法读取带有linkedState的reactJs中的null值

Javascript 无法读取带有linkedState的reactJs中的null值,javascript,reactjs,Javascript,Reactjs,我正在尝试在react中创建一个复选框组件,因为我已经有了四个复选框组件,而且以后可能还会添加更多,所以我认为使用reactLink将有助于减少代码的冗长。但是,我不断收到一个错误,它是uncaughttypeerror:cannotreadproperty'false'of null 这里是组件骨骼,注意我还没有处理更改-尝试一次处理一件事情 var NewCheckInput = React.createClass({ mixins: [React.addons.L

我正在尝试在react中创建一个复选框组件,因为我已经有了四个复选框组件,而且以后可能还会添加更多,所以我认为使用reactLink将有助于减少代码的冗长。但是,我不断收到一个错误,它是
uncaughttypeerror:cannotreadproperty'false'of null

这里是组件骨骼,注意我还没有处理更改-尝试一次处理一件事情

var NewCheckInput = React.createClass({

            mixins: [React.addons.LinkedStateMixin],
            render: function(){

                    var filter = this.props.listFilters;
                    var inputData = this;
                    console.log(filter);
                    console.log(this.props.inputValue);

                    var input = (<input
                        type="checkbox"
                        onChange={this.handleChange}
                        name={inputData.props.inputId}
                        checked={this.props.inputValue}
                        id={inputData.props.inputId}
                        checkedLink={this.linkState(filter.for_sale)} />);

                    var label = (
                        <label htmlFor={inputData.props.inputId}>
                            {inputData.props.inputName}
                        </label>);

                    if (this.props.inputLabel){

                    var inputSection = <section>{input} {label}</section>
                    } else {
                        var inputSection  = <section>{input}</section>
                    }

                return inputSection
            }
        });

请原谅,如果这里有一些愚蠢的编码,仍然在进行最佳实践、正确模式等工作。

首先,这里引用facebook的react:

如果您是框架新手,请注意,大多数应用程序都不需要ReactLink,应谨慎使用

所以我建议你不要使用linkState。(由你决定)

下面是检查组件的代码

“严格使用”;
var React=要求('React');
var CheckBox=React.createClass({
道具类型:{
名称:React.PropTypes.string,
选中:React.PropTypes.bool,
描述:React.PropTypes.string,
checkStatusChanged:React.PropTypes.func
},
getDefaultProps:function(){
返回{
名称:“”,
勾选:假,
说明:“”,
checkStatusChanged:函数(){}
};
},
getInitialState:函数(){
返回{
检查:这个。道具。检查
};
},
_handleCheckChanged:函数(事件){
this.props.checkStatusChanged(this.props.name,event.target.checked);
this.setState({checked:event.target.checked});
},
render:function(){
/*jshint忽略:开始*/
返回(
{this.props.description}
);
/*jshint忽略:结束*/
}
});

module.exports=复选框链接状态用于设置状态,在您的示例中,它似乎链接到一个变量。如果希望链接到某个状态,请在getInitialState中声明该状态,然后链接到该名称。这里有更多的信息和示例:所以,我确实在我的应用程序根目录下的FilterGrid类中设置了我的状态,然后将状态传递给我的子应用程序-理论上,我的目标是相同的状态名称-这不是正确的方法吗?我对你想做什么有点困惑。在“ControlPerform”表单中有“NewCheckInput”组件。是否希望从“ControlPerform”控制每个“NewCheckInput”?您通过道具将状态传递给子对象,子对象通过道具函数将值传递回父对象。状态在组件内部使用。Clearify me,也许我可以给你一些代码示例NewCheckInput接收唯一的prop值,该值返回一个构造的表单元素和关联的元(名称、id等),并有一个指向关联状态的valueLink(也从父级传下来,也称为状态所有者)。。。至少我是这么想的。
var ControllerForm = React.createClass({

            render: function(){
                var filter = this.props.listFilters;
                return (
                    <form>
                    <NewCheckInput
                        inputType="checkbox"
                        inputId="for-sale"
                        refs="for_sale"
                        inputName="For Sale (3+ Years)"
                        inputLabel ="true"
                        inputValue={filter.for_sale}
                        {...this.props} />

                    </form>
                    )
            }
        });
var FilterGrid = React.createClass({
            mixins: [React.addons.LinkedStateMixin],
            getInitialState: function(){
                return {
                    search: '',
                    all: true,
                    for_sale: false,
                    zuchtstuten: false,
                    nachzucht: false
                }
            },

            render: function() {
                return (<section className="wrapper filter-grid">
                    <GridController listFilters={this.state} />
                    <GridList listFilters={this.state} items={horseArr} />
                    </section>)
                }
        });

        React.render(
            <FilterGrid/>,
            document.getElementById('filter-grid')
            );
Object {search: "", all: true, for_sale: false, zuchtstuten: false, nachzucht: false}