【发布时间】:2019-02-19 22:43:06
【问题描述】:
我在 react js 应用中使用下拉菜单,但 onChange 没有触发
我的代码是
import React from "react";
import PropTypes from "prop-types";
import Dropdown from 'react-dropdown';
const options = [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two', className: 'myOptionClassName' },
];
class WebDashboardPage extends React.Component {
constructor(props) {
super(props);
this.state = {}
}
quan = (event)=> {
console.log("Option selected:");
this.setState({ value: event.target.value });
};
render() {
return(
<b><Dropdown className="dropdownCss" options={options} onChange={e =>
this.quan(e.target.value)} /></b>
);
}
当我单击下拉列表中的项目时,它会显示错误
"TypeError: 无法读取未定义的属性 'quan'"
我是反应新手 提前致谢
【问题讨论】:
-
这应该是 onChange={e => this.quan(e)} 或 onChange={this.quan}
-
它不工作显示同样的错误
-
您在组件的任何位置都定义了两次 quan 吗?因为 quan 是您代码中的一个函数,但错误表示属性,所以您必须在组件中的其他位置定义 quan
-
@Think-Twice 我彻底检查了我的代码中没有其他 quan
-
好吧,做一件事在线托管您的代码并分享链接,或者在这里分享您的所有代码,这是帮助您的唯一方法
标签: javascript reactjs drop-down-menu react-redux react-component