代码之家  ›  专栏  ›  技术社区  ›  John

第一次渲染后反应组件丢失道具

  •  1
  • John  · 技术社区  · 7 年前

    在这个组件中,我使用createContainer访问集合,并调用会话变量,以便使用findOne查询集合。当我第一次渲染组件时,一切正常,集合被正确查询。但是在控制台中。日志方法。我将有准确的信息显示在渲染,然后立即相同的变量将被取消定义。

    import React from 'react';
    import { Email } from 'meteor/email';
    import { createContainer } from 'meteor/react-meteor-data';
    
    import {Tickets} from './tickets';
    
    class ClaimButton extends React.Component {
      constructor(props){
        super(props);
        this.state = {
          senderEmail: '',
          senderPhone: '',
          senderMessage: '',
          error: '',
          person: '',
          city: '',
          quantity: '',
          ticketNum: '',
          orderSum: ''
        }
        this.onClaimRequest = this.onClaimRequest.bind(this);
      }
    
      onClaimRequest(e) {
        e.preventDefault();
        const {ticket} = this.props
        const claimTicketData = { person, city, quantity, ticketNum, orderSum };
        this.setState(claimTicketData);
        const {tikDta} = this.state;
        console.log(tikDta);
        let receiver = Meteor.settings.public.RECEIVER;
        Meteor.call('sendEmail',
          receiver,
          this.refs.senderEmail.value,
          'An event was claimed.',
          `Dear coordinator, A user claiming to be: ${tikDta.person} has initiated a claim in ${tikDta.city}, of ${tikDta.quantity}, at ${tikDta.ticketNum} ticket(s).  A total of ${tikDta.orderSum}.  During this version, please contact them directly to confirm their claim.
          Email: ${ this.refs.senderEmail.value}
          Phone:  ${this.refs.senderPhone.value}.
          Sender Message: ${ this.refs.senderMessage.value }
          Ticket Id Number: ${this.props.ticket._id}`
        );
    }
    
      render() {
        console.log('claimButton', this.props.ticket);
        return (
          <div>
            <h1 className="form-title">Claiming Ticket?</h1>
            <h2>Are you {this.props.ticket.person}?  Ready to claim {this.props.ticket.orderSum} in {this.props.ticket.city}? </h2>
            <h2>Quantity: {this.props.ticket.quantity}</h2>
    
            <form onSubmit={this.onClaimRequest}>
              <div className="form-group">
                <label htmlFor="senderEmail">Email address</label>
                <input type="email" ref="senderEmail" className="form-control" id="senderEmail1" placeholder="Email" />
              </div>
              <div className="form-group">
                <label htmlFor="SenderPhone">Contact telephone</label>
                <input type="tel" ref="senderPhone" className="form-control" id="SenderPhone1"/>
              </div>
              <div className="form-group">
                <label htmlFor="SenderMessage">Messsage us</label>
                <textarea ref="senderMessage" className="form-control" rows="3"></textarea>
              </div>
              <div>
                <button className="btn btn-default" type="submit">Claim</button>
              </div>
            </form>
          </div>
        )
      }
    }
    
    
    export default createContainer(() => {
      const claimedTicket = Session.get('claimedTicket');
      Meteor.subscribe('tickets.claimed');
      const ticket = Tickets.findOne(claimedTicket);
      // console.log(ticket);
      return {ticket}
    }, ClaimButton);
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   rstumbaugh    7 年前

    ClaimButton render()