Twitter bootstrap REACTJS-需要帮助将表行数据传递给模态类吗
我只想将表中所有的行数据传递给modal类并调用每个数据,但我仍在学习react。目前我的模态类仍然是静态数据。我真的很想学习react,请帮助我如何将所有行数据传递给modal类。这是我目前的密码 模态类数据仍然是静态的Twitter bootstrap REACTJS-需要帮助将表行数据传递给模态类吗,twitter-bootstrap,reactjs,redux,Twitter Bootstrap,Reactjs,Redux,我只想将表中所有的行数据传递给modal类并调用每个数据,但我仍在学习react。目前我的模态类仍然是静态数据。我真的很想学习react,请帮助我如何将所有行数据传递给modal类。这是我目前的密码 模态类数据仍然是静态的 class Modal extends React.Component { constructor (props) { super(props) this.state = { modalOpened: false } this.modalToggle = this.m
class Modal extends React.Component {
constructor (props) {
super(props)
this.state = {
modalOpened: false
}
this.modalToggle = this.modalToggle.bind(this)
}
modalToggle () {
this.setState({ modalOpened: !this.state.modalOpened })
}
render () {
const coverClass = this.state.modalOpened ? 'modal-cover modal-cover-active'
: 'modal-cover'
const containerClass = this.state.modalOpened ? 'modal-container modal-container-active' : 'modal-container'
return (
<div>
<button className='btn btn-primary' onClick={this.modalToggle}>View</button>
<div className={containerClass}>
<div className='modal-header'>
<button type="button" className="close" data-dismiss="modal" onClick={this.modalToggle}><span aria-hidden="true">×</span><span className="sr-only" >Close</span></button>
<h4 className="modal-title" id="myModalLabel">Number: 11231564243</h4>
</div>
<div className='modal-body'>
<table>
<tbody>
<tr>
<td>Status:</td>
<td>NEW</td>
</tr>
</tbody>
</table>
</div>
<div className='modal-footer'>
<button type="button" className="btn-primary" data-dismiss="modal" onClick={this.modalToggle}>Close</button>
</div>
</div>
<div className={coverClass} onClick={this.modalToggle}></div>
</div>
)
}
}
类模态扩展React.Component{
建造师(道具){
超级(道具)
此.state={
莫达洛佩:错
}
this.modalToggle=this.modalToggle.bind(this)
}
modalToggle(){
this.setState({modalOpened:!this.state.modalOpened})
}
渲染(){
const coverClass=this.state.modalOpened?“模态覆盖模态覆盖激活”
:“模式封面”
const containerClass=this.state.modalOpened?“模态容器模态容器活动”:“模态容器”
返回(
看法
&接近
电话:11231564243
地位:
新的
接近
)
}
}
const行=({日期、Id、名称、标题、状态,
索引})=>(
{Date}
{Id}
{Name}
{Title}
{状态}
);
表类------------------------------
class Table extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [
{
Date: '',
Id: '',
Name: '',
Title: '',
Status: ''
},
],
};
this.compareBy.bind(this);
this.sortBy.bind(this);
}
componentWillReceiveProps(nextProps) {
if( Object.keys(nextProps.orders).length) {
this.setState({data: nextProps.orders});
}
}
compareBy(key) {
return function (a, b) {
if (a[key] < b[key]) return -1;
if (a[key] > b[key]) return 1;
return 0;
};
}
sortBy(key) {
let arrayCopy = [...this.state.data];
arrayCopy.sort(this.compareBy(key));
this.setState({data: arrayCopy});
}
render() {
const rows = this.state.data.map( (rowData, index) => <Row {...rowData} index={index} />);
return (
<table>
<thead>
<tr>
<th onClick={() => this.sortBy('Date')} >Date</th>
<th onClick={() => this.sortBy('Id')}>ID</th>
<th onClick={() => this.sortBy('Name')}>Name</th>
<th onClick={() => this.sortBy('Title')}>Title</th>
<th onClick={() => this.sortBy('Status')}>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{rows}
</tbody>
</table>
);
}
}
export class OrdersView extends React.Component {
//API Data-----------------------------------
constructor(props) {
super(props)
this.state = {
saved: false,
orders: {},
value: ''
};
}
//onchange start date
handleOnChangeFrom(e) {
this.setState({
from: e.target.value,
});
}
//onchange end date
handleOnChangeTo(e) {
this.setState({
to: e.target.value,
});
}
filterClick = () => {
// @notice, call the api endpoint only when the component has been mounted.
//EXAMPLE Orders retrieval
//this.state.from and this.state.to value are passed on handleonchange
//npm install dateformat
var dateFormat = require('dateformat');
var dStart = this.state.from;
var dEnd= this.state.to;
var dateStart = dateFormat(dStart, "dd/mm/yyyy");
var dateEnd = dateFormat(dEnd, "dd/mm/yyyy");
const params = {
startDate: dateStart,
endDate: dateEnd,
}
LambdaService.getOrdersAsync(params)
.then((orders) => {
this.setState({
orders: orders
});
})
.catch(err => {
alert('no orders available on the selected range of date');
});
}
render () {
const {username} = this.props;
const bgStyle = {background: "url(img/sample.jpg)"};
const {
orders: orders
} = this.state
return (
<div className='col-xs-12 col-no-padding col-stretch-children dashboard'>
<Title render='My Orders' />
<div className='StatusColumn details col-lg-3 col-md-3 col-sm-12 col-xs-12' style={bgStyle}>
<div className="StatusColumnInner">
<h3 className='dashboard--header'>{username} Order's</h3>
</div>
</div>
<div className='details col-main-content col-lg-9 col-md-9 col-sm-12 col-xs-12'>
<div className='MainColumn'>
<span className='order-span-style'>From </span>
<input type="date" id="from" value={this.state.from} onChange={ (e) => this.handleOnChangeFrom(e) } />
<span className='order-span-style'>To </span>
<input type="date" id="to" value={this.state.to} onChange={ (e) => this.handleOnChangeTo(e) } />
<button className="button-order-style" onClick={this.filterClick.bind(this)}>Run Report</button>
<Table orders={orders}></Table>
</div>
</div>
</div>
)
}
}
OrdersView.propTypes = {
username: PropTypes.string,
}
export default OrdersView
类表扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
数据:[
{
日期:'',
Id:“”,
名称:“”,
标题:“”,
状态:“”
},
],
};
this.compareBy.bind(this);
这个。肮脏。捆绑(这个);
}
组件将接收道具(下一步){
if(Object.keys(nextrops.orders).length){
this.setState({data:nextrops.orders});
}
}
比较(键){
返回函数(a,b){
如果(a[key]b[key])返回1;
返回0;
};
}
索特比(钥匙){
让arrayCopy=[…this.state.data];
arrayCopy.sort(this.compareBy(key));
this.setState({data:arrayCopy});
}
render(){
const rows=this.state.data.map((rowData,index)=>);
返回(
this.sortBy('Date')}>Date
this.sortBy('Id')}>Id
this.sortBy('Name')}>Name
this.sortBy('Title')}>Title
this.sortBy('Status')}>Status
行动
{rows}
);
}
}
父类--------------------------
class Table extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [
{
Date: '',
Id: '',
Name: '',
Title: '',
Status: ''
},
],
};
this.compareBy.bind(this);
this.sortBy.bind(this);
}
componentWillReceiveProps(nextProps) {
if( Object.keys(nextProps.orders).length) {
this.setState({data: nextProps.orders});
}
}
compareBy(key) {
return function (a, b) {
if (a[key] < b[key]) return -1;
if (a[key] > b[key]) return 1;
return 0;
};
}
sortBy(key) {
let arrayCopy = [...this.state.data];
arrayCopy.sort(this.compareBy(key));
this.setState({data: arrayCopy});
}
render() {
const rows = this.state.data.map( (rowData, index) => <Row {...rowData} index={index} />);
return (
<table>
<thead>
<tr>
<th onClick={() => this.sortBy('Date')} >Date</th>
<th onClick={() => this.sortBy('Id')}>ID</th>
<th onClick={() => this.sortBy('Name')}>Name</th>
<th onClick={() => this.sortBy('Title')}>Title</th>
<th onClick={() => this.sortBy('Status')}>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{rows}
</tbody>
</table>
);
}
}
export class OrdersView extends React.Component {
//API Data-----------------------------------
constructor(props) {
super(props)
this.state = {
saved: false,
orders: {},
value: ''
};
}
//onchange start date
handleOnChangeFrom(e) {
this.setState({
from: e.target.value,
});
}
//onchange end date
handleOnChangeTo(e) {
this.setState({
to: e.target.value,
});
}
filterClick = () => {
// @notice, call the api endpoint only when the component has been mounted.
//EXAMPLE Orders retrieval
//this.state.from and this.state.to value are passed on handleonchange
//npm install dateformat
var dateFormat = require('dateformat');
var dStart = this.state.from;
var dEnd= this.state.to;
var dateStart = dateFormat(dStart, "dd/mm/yyyy");
var dateEnd = dateFormat(dEnd, "dd/mm/yyyy");
const params = {
startDate: dateStart,
endDate: dateEnd,
}
LambdaService.getOrdersAsync(params)
.then((orders) => {
this.setState({
orders: orders
});
})
.catch(err => {
alert('no orders available on the selected range of date');
});
}
render () {
const {username} = this.props;
const bgStyle = {background: "url(img/sample.jpg)"};
const {
orders: orders
} = this.state
return (
<div className='col-xs-12 col-no-padding col-stretch-children dashboard'>
<Title render='My Orders' />
<div className='StatusColumn details col-lg-3 col-md-3 col-sm-12 col-xs-12' style={bgStyle}>
<div className="StatusColumnInner">
<h3 className='dashboard--header'>{username} Order's</h3>
</div>
</div>
<div className='details col-main-content col-lg-9 col-md-9 col-sm-12 col-xs-12'>
<div className='MainColumn'>
<span className='order-span-style'>From </span>
<input type="date" id="from" value={this.state.from} onChange={ (e) => this.handleOnChangeFrom(e) } />
<span className='order-span-style'>To </span>
<input type="date" id="to" value={this.state.to} onChange={ (e) => this.handleOnChangeTo(e) } />
<button className="button-order-style" onClick={this.filterClick.bind(this)}>Run Report</button>
<Table orders={orders}></Table>
</div>
</div>
</div>
)
}
}
OrdersView.propTypes = {
username: PropTypes.string,
}
export default OrdersView
导出类OrdersView扩展了React.Component{
//API数据-----------------------------------
建造师(道具){
超级(道具)
此.state={
保存:错误,
命令:{},
值:“”
};
}
//更改开始日期
从(e)到(e){
这是我的国家({
来源:e.target.value,
});
}
//更改结束日期
更改为(e){
这是我的国家({
致:即目标价值,
});
}
过滤器点击=()=>{
//@注意,仅当组件已装入时才调用api端点。
//订单检索示例
//this.state.from和this.state.to值在更改时传递
//npm安装日期格式
var dateFormat=require('dateFormat');
var dStart=this.state.from;
var dEnd=this.state.to;
var dateStart=dateFormat(dStart,“dd/mm/yyyy”);
var dateEnd=dateFormat(dEnd,“dd/mm/yyyy”);
常量参数={
开始日期:日期开始,
endDate:dateEnd,
}
LambdaService.getOrdersAsync(参数)
。然后((订单)=>{
这是我的国家({
订单:订单
});
})
.catch(错误=>{
警报(“所选日期范围内无可用订单”);
});
}
渲染(){
const{username}=this.props;
constbgstyle={background:“url(img/sample.jpg)”};
常数{
订单:订单
}=这个州
返回(
{username}订单的
从…起
此.handleon从(e)}/>
到
此.handleon更改为(e)}/>
运行报告
)
}
}
OrdersView.propTypes={
用户名:PropTypes.string,
}
导出默认订单视图
经过几个小时的研究,我找到了答案
我将所有的值添加到模式按钮
const Row = ({Date, Id, Name, Title, Status,
Quantity, Price, index}) => (
<tr key={index}>
<td>{Date}</td>
<td>{Id}</td>
<td>{Name}</td>
<td>{Title}</td>
<td>{Status}</td>
<td>
<Modal
OrderDate = {Date}
OrderId = {Id}
AddictName = {Name}
ProductTitle = {Title}
OrderStatus = {Status}
Quantity = {Quantity}
UnitPrice = {Price}
index = {index}
/>
</td>
</tr>
);
const行=({日期、Id、名称、标题、状态,
数量、价格、指数})=>(
{Date}
{Id}
{Name}
{Title}
{状态}
);
并使用以下示例{this.props.Status}将数据调用到modal
class Modal extends React.Component {
constructor (props) {
super(props)
this.state = {
modalOpened: false
}
this.modalToggle = this.modalToggle.bind(this)
}
modalToggle () {
this.setState({ modalOpened: !this.state.modalOpened })
}
render () {
const coverClass = this.state.modalOpened ? 'modal-cover modal-cover-active'
: 'modal-cover'
const containerClass = this.state.modalOpened ? 'modal-container modal-
container-active' : 'modal-container'
return (
<div>
<button className='btn btn-primary' onClick={this.modalToggle}>View</button>
<div className={containerClass}>
<div className='modal-header'>
<button type="button" className="close" data-dismiss="modal" onClick=
{this.modalToggle}><span aria-hidden="true">×</span><span
className="sr-only" >Close</span></button>
<h4 className="modal-title" id="myModalLabel">Number: 11231564243</h4>
</div>
<div className='modal-body'>
<table>
<tbody>
<tr>
<td>Status:</td>
<td>{this.props.Status}</td>
</tr>
</tbody>
</table>
</div>
<div className='modal-footer'>
<button type="button" className="btn-primary" data-dismiss="modal" onClick={this.modalToggle}>Close</button>
</div>
</div>
<div className={coverClass} onClick={this.modalToggle}></div>
</div>
)
}
}
类模态扩展React.Component{
建造师(道具){
超级(道具)
此.state={
莫达洛佩:错
}
this.modalToggle=this.modalToggle.bind(this)
}
modalToggle(){
this.setState({modalOpened:!this.state.modalOpened})
}
渲染(){
const coverClass=this.state.modalOpened?“模态覆盖模态覆盖激活”
:“模式封面”
const container class=this.state.modalOpened?“模态容器模态”-
容器活动“:“模式容器”
返回(
看法
&接近
电话:11231564243
地位:
{this.props.Status}
接近
)
}
}
经过几个小时的研究,我找到了答案
我将所有的值添加到模式按钮
const Row = ({Date, Id, Name, Title, Status,
Quantity, Price, index}) => (
<tr key={index}>
<td>{Date}</td>
<td>{Id}</td>
<td>{Name}</td>
<td>{Title}</td>
<td>{Status}</td>
<td>
<Modal
OrderDate = {Date}
OrderId = {Id}
AddictName = {Name}
ProductTitle = {Title}
OrderStatus = {Status}
Quantity = {Quantity}
UnitPrice = {Price}
index = {index}
/>
</td>
</tr>
);
const行=({日期、Id、名称、标题、状态,
数量、价格、指数})=>(
{Date}
{Id}
{Name}
{Title}
{状态}
);
并使用以下示例{this.props.Status}将数据调用到modal
class Modal extends React.Component {
constructor (props) {
super(props)
this.state = {
modalOpened: false
}
this.modalToggle = this.modalToggle.bind(this)
}
modalToggle () {
this.setState({ modalOpened: !this.state.modalOpened })
}
render () {
const coverClass = this.state.modalOpened ? 'modal-cover modal-cover-active'
: 'modal-cover'
const containerClass = this.state.modalOpened ? 'modal-container modal-
container-active' : 'modal-container'
return (
<div>
<button className='btn btn-primary' onClick={this.modalToggle}>View</button>
<div className={containerClass}>
<div className='modal-header'>
<button type="button" className="close" data-dismiss="modal" onClick=
{this.modalToggle}><span aria-hidden="true">×</span><span
className="sr-only" >Close</span></button>
<h4 className="modal-title" id="myModalLabel">Number: 11231564243</h4>
</div>
<div className='modal-body'>
<table>
<tbody>
<tr>
<td>Status:</td>
<td>{this.props.Status}</td>
</tr>
</tbody>
</table>
</div>
<div className='modal-footer'>
<button type="button" className="btn-primary" data-dismiss="modal" onClick={this.modalToggle}>Close</button>
</div>
</div>
<div className={coverClass} onClick={this.modalToggle}></div>
</div>
)
}
}
类模态扩展React.Component{
建造师(道具){
超级(道具)
此.state={
莫达洛佩:错
}
this.modalToggle=this.modalToggle.bind(this)
}
modalToggle(){
this.setState({modalOpened:!this.state.modalOpened})
}
渲染(){
const coverClass=this.state.modalOpened?“模态覆盖模态覆盖激活”
:“模式封面”
const container class=this.state.modalOpened?“模态容器模态”-
容器活动“:“模式容器”
返回(
看法
&接近
电话:11231564243
地位:
{this.props.Status}
接近
)
}
}