material ui:selectfiled multiple property

时间:2018-03-15 11:26:18

标签: reactjs material-ui

我使用的是材料ui,我想使用mutliple属性,但是我有一个错误: multiple does not exist on the type selectfiled

<SelectField
    multiple={true} //it doesn't work        
    value={this.state.valueProfession}
    onChange={this.handleChangeProfession}></SelectField>

我有材料ui的版本0.16.5。我想避免更新材料ui的最新版本。还有其他解决方案吗?谢谢

1 个答案:

答案 0 :(得分:0)

请将您的0.16.5版更新到更新版本以便使用它。 我在版本0.18.4中使用过它

以下是简单的工作示例

import React from 'react';
import SelectField from 'material-ui/SelectField';
import MenuItem from 'material-ui/MenuItem';

const names = [
    'Oliver Hansen',
    'Van Henry',
    'April Tucker',
    'Ralph Hubbard',
    'Omar Alexander',
    'Carlos Abbott',
    'Miriam Wagner',
    'Bradley Wilkerson',
    'Virginia Andrews',
    'Kelly Snyder',
];

/**
 * `SelectField` can handle multiple selections. It is enabled with the `multiple` property.
 */
export default class SelectFieldExampleMultiSelect extends React.Component {
    state = {
        values: [],
    };

    handleChange = (event, index, values) => this.setState({values});

    menuItems(values) {
        return names.map((name) => (
            <MenuItem
                key={name}
                insetChildren={true}
                checked={values && values.indexOf(name) > -1}
                value={name}
                primaryText={name}
            />
        ));
    }

    render() {
        const {values} = this.state;
        return (
            <SelectField
                multiple={true}
                hintText="Select a name"
                value={values}
                onChange={this.handleChange}
            >
                {this.menuItems(values)}
            </SelectField>
        );
    }
}