React.js - REF undefined
React.js - REF undefined
当我测试以下代码时,我收到一个控制台错误,newText
未定义,我是正确地声明了val var,还是遗漏了什么?
val = ReactDOM.findDOMNode(this.refs[newText]);
renderForm: function() {
return (
<div className="note">
<textarea ref="newText" defaultValue={this.props.children} className="form-control"></textarea>
<button onClick={this.save} className="btn btn-success btn-sm glyphicon glyphicon-floppy-disk"></button>
</div>
)
},
newText
这里需要是字符串("newText"
),或者应该使用点表示法。仅使用newText
意味着您正在尝试读取具有该名称的变量的值(它将返回undefined
)。
更改:
this.refs[newText]
收件人:
this.refs["newText"]
或者:
this.refs.newText
我知道现在回答这个问题已经很晚了,但我遇到了同样的问题。
我添加并更新了以下来源:src="https://unpkg.com/react@15/dist/areact.js">src="https://unpkg.com/react-dom@15/dist/rect dom.js">
它对我有效。
希望你已经找到了解决方案。干杯
使用this.refs.newText
而不是this.refs[newText]
。
相关文章:
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- /undefined在我的404错误日志中多次出现
- RequireJS向模块传递配置总是返回undefined
- JSON数组数据返回Undefined
- 为什么会出现错误,“UncaughtTypeError:undefined不是函数”
- Array.lenght = undefined
- mongoose.connect undefined不是一个函数
- JavaScript”;.方法“;返回undefined
- Uncaught TypeError:undefined不是函数-ember js
- Jquery - table.row(tr) is undefined
- jQuery可以't获取data-*属性值,返回undefined
- noty.js is returning undefined
- 将对象的列表c#传递给javascript:undefined变量时出错
- $routeParams is undefined
- 试图打印/调用/或提醒数组中的对象:Getting Undefined
- jQuery Mobile Undefined不是一个函数
- Javascript/JSON警报返回Undefined
- React.js - REF undefined
- 为什么我的React组件's ref在测试中等于undefined ?
- this.ref .something.value在react中返回undefined