【发布时间】:2019-02-21 03:22:45
【问题描述】:
我还是新手,我必须创建这个图标菜单。我的问题是我的 handleChange 现在不起作用。我有图标菜单,我可以看到 possibleValues 菜单,但我无法选择其中任何一个。有人可以解释使此代码工作的最佳方法吗?我正在使用图标菜单组件“https://v0.material-ui.com/#/components/icon-menu”。谢谢
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import SelectField from 'material-ui/SelectField';
import MenuItem from 'material-ui/MenuItem';
class MatchPintOwnerFilter extends Component {
constructor() {
super();
this.state = {
values: [],
};
}
handleChange(event, index, values) {
this.setState({ values });
}
render() {
const { possibleValues, title } = this.props;
return (
<SelectField
autoWidth
floatingLabelText={title}
multiple={false}
value={possibleValues}
onChange={this.handleChange.bind(this)}
>
{Object.keys(possibleValues).map(possibleValue => (
<MenuItem
key={possibleValue}
value={possibleValue}
primaryText={possibleValues[possibleValue]}
/>
))}
</SelectField>
);
}
}
MatchPintOwnerFilter.propTypes = {
title: PropTypes.string,
possibleValues: PropTypes.shape(),
newValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};
MatchPintOwnerFilter.defaultProps = {
title: 'Frequency',
possibleValues: {
0: 'status 0',
1: 'status 1',
2: 'status 2',
3: 'status 3',
4: 'status 4',
5: 'status 5',
},
newValue: '1',
};
export default MatchPintOwnerFilter;
【问题讨论】:
-
在您共享的代码的 sn-p 中,您使用的是 SelectField。
标签: javascript reactjs material-ui