Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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 React.js如何在内部组件中查找ref元素_Javascript_Reactjs - Fatal编程技术网

Javascript React.js如何在内部组件中查找ref元素

Javascript React.js如何在内部组件中查找ref元素,javascript,reactjs,Javascript,Reactjs,我想与组件共享从onChange事件到父组件的数据我不知道该怎么做 您知道如何在组件和其父组件之间共享数据吗 ViewTwoComponent他们看不到ref值,我不知道为什么 控制台上出现错误:未捕获的TypeError:无法读取未定义的属性“getDOMNode” var viewtowcomponent=React.createClass({ “getInitialState”:函数(){ 返回{ “userTextValue”:“Hello11111111”, “userTextRef”

我想与组件共享从onChange事件到父组件的数据我不知道该怎么做

您知道如何在组件和其父组件之间共享数据吗

ViewTwoComponent他们看不到ref值,我不知道为什么

控制台上出现错误:未捕获的TypeError:无法读取未定义的属性“getDOMNode”

var viewtowcomponent=React.createClass({
“getInitialState”:函数(){
返回{
“userTextValue”:“Hello11111111”,
“userTextRef”:“userTextRef”
}
},
“更新状态”:功能(值){
this.setState({userTextValue:value})
},
“handleChange”:函数(){
this.updateState(this.refs.userTextRef.getDOMNode().value)
},
“render”:函数(){
返回
;
}
})
var Inner=React.createClass({
“render”:函数(){
返回内部;
}
});
var Filtering=React.createClass({
“render”:函数(){
返回
;
}
});
React.render(,document.getElementById(“内部”))

当您尝试引用
this.refs.userTextRef
时,您的意思有点混乱,但我假设您想要处于您的状态的值。我还将假设键
userTextRef
的值实际上不是
userTextRef
。您可以尝试使用方括号访问该值

  "handleChange": function() {
    this.updateState(this.refs[userTextRef]getDOMNode().value)
  }

我是新手,但根据我对教程的记忆,您应该将
过滤
组件的函数传递给
视图组件

var Filtering = React.createClass({
        "childChanged" : function(child, value) {
           console.log("child: " + child + "change value to: " value);
        },
        "render": function() {
            return <span>
                <input type="text" ref={this.props.refName} onChange={this.props.handleChange} value={this.props.userTextValue} notifyParent={this.childChanged} />
            </span>;
        }
    });
var筛选=React.createClass({
“childChanged”:函数(子级,值){
log(“child:+child+”将值更改为:“value”);
},
“render”:函数(){
返回
;
}
});
然后,在
ViewTwoComponent
类的
handleChange
方法中,调用
this.props.notifyParent(this,this.state.userTextValue)

我想与组件共享从onChange事件到父组件的数据,但我不知道如何实现。
var Filtering = React.createClass({
        "childChanged" : function(child, value) {
           console.log("child: " + child + "change value to: " value);
        },
        "render": function() {
            return <span>
                <input type="text" ref={this.props.refName} onChange={this.props.handleChange} value={this.props.userTextValue} notifyParent={this.childChanged} />
            </span>;
        }
    });