所用组件均来自material ui 所用实例代码为自己封装的一个新组件
首先安装meterial ui 组件 https://github.com/callemall/material-ui实现Dialog弹窗
其次安装select组件: https://github.com/JedWatson/react-select 实现select
dialog源代码及效果:https://github.com/JedWatson/react-select
select源代码及效果:https://github.com/JedWatson/react-select#async-options-with-promises https://jedwatson.github.io/react-select/
以下为封装代码
效果:点击BUTTON按钮后,会弹出一个Dialog,Dialog中是muilt Select选择框`</pre>
</div>
[Select-Dialog](http://115.159.42.92/wp-content/uploads/2016/08/Select-Dialog.txt)
[![Dialog](http://www.ihongguang.cn/wp-content/uploads/2016/08/Dialog-300x196.png)](http://www.ihongguang.cn/wp-content/uploads/2016/08/Dialog.png)
css代码:[Select-Dialog](http://www.ihongguang.cn/wp-content/uploads/2016/08/Select-Dialog.txt)
<div>
<pre>` import React from 'react';
import Dialog from 'material-ui/lib/Dialog';
import RaisedButton from 'material-ui/lib/raised-button';
import Select from 'react-select';
/*select选项*/
const FLAVOURS = [
{ label: 'banana', value: 'banana' },
{ label: 'apple', value: 'apple' },
{ label: 'paire', value: 'paire' },
{ label: 'ori', value: 'ori' },
{ label: 'red', value: 'red' },
{ label: 'yellow', value: 'yellow' },
{ label: 'blue', value: 'blue' },
{ label: 'pink', value: 'pink' },
{ label: 'banana', value: 'banana' },
{ label: 'apple', value: 'apple' },
{ label: 'paire', value: 'paire' },
{ label: 'ori', value: 'ori' },
{ label: 'red', value: 'red' },
{ label: 'yellow', value: 'yellow' },
{ label: 'blue', value: 'blue' },
{ label: 'pink', value: 'pink' },
];
export default React.createClass({
propTypes: {
label: React.PropTypes.string,
},
getInitialState: function () {
return {
options: FLAVOURS, projectMembers: [],
projectMonitor:[],
newProject: false,
};
},
handleOpenForProject :function (){
this.setState({newProject:true});
},
handleClose :function (){
/*if判断*/
if(this.state.newProject==true)
{
this.setState({newProject:false});
this.setState({projectMonitor:null});
this.setState({projectMembers:null});
}
},
handleSelectProjectMember :function(projectMembers) {
this.setState({ projectMembers });
},
handleSelectProjectMonitor :function(projectMonitor) {
this.setState({ projectMonitor });
},
render() {
const actions =
[
<RaisedButton label="Cancel" primary={true} onClick={this.handleClose} />,
<RaisedButton label="Submit" primary={true} onTouchTap={this.handleClose} />,
];
return (
<div >{/*点击此按钮*/}
<RaisedButton label="New Project"primary={true} onClick={this.handleOpenForProject} />
BUTTON
<Dialog
actions={actions}
modal={false}
open={this.state.newProject}
onRequestClose={this.handleClose} >
<div id="Dialog_Title">
<h2 id="title">Add a new project</h2><br/>
</div>
<div id="textField">
<div className="section">
<Select multi simpleValue value={this.state.projectMonitor} options={this.state.options} placeholder="Select Monitor" onChange={this.handleSelectProjectMonitor} />
</div>
<div className="section">
<Select multi simpleValue value={this.state.projectMembers} options={this.state.options} placeholder="Select Members" onChange={this.handleSelectProjectMember} />
</div>
</div>
</Dialog>
</div>
);
}
})