【问题标题】:Display a value from firebase to a page while opening it在打开页面时将值从 firebase 显示到页面
【发布时间】:2018-11-09 05:47:44
【问题描述】:

有一个添加拍卖页面,添加拍卖时打开添加拍卖页面时默认显示拍卖编号。

在我的情况下,仅在单击并尝试添加数字或退出该字段后才会显示该数字。并且该数字将根据我们已经添加的计数来自火力基地,当前拍卖数量应该像现有拍卖加一(现有拍卖计数 + 1)。提前致谢!!

render() {
const { handleSubmit } = this.props;
let chittieAuctionNumber = Object.keys(this.props.chittieAuctions).length;
let chittieAuctionUsers = [];
let chittieId = this.props.match.params.chittieId;
let chittieUsers = this.props.chitties[chittieId].chittieUsers;
Object.keys(this.props.chittieAuctions).map((key) => {
  chittieAuctionUsers.push(this.props.chittieAuctions[key].userData);
});
Object.keys(this.props.chitties[chittieId].chittieUsers).map((key) => {
  let existingUserData = find(chittieAuctionUsers, ['id', key]);
  if (existingUserData && existingUserData.id === key) {
    delete chittieUsers[key];
  }
});
const auctionNumber = (value) =>
  value == null ? '' : chittieAuctionNumber + 1;

return (
  <form onSubmit={handleSubmit}>
    <Card>
      <CardHeader>
        <Row>
          <Col xs="6" lg="5">
            <Button color="primary" onClick={this.goBack}>
              <i className="fa fa-chevron-left" />
              &nbsp;Back
            </Button>
          </Col>
          <Col xs="6" lg="7">
            <h4 className="font-weight-bold">Add Auction</h4>
          </Col>
        </Row>
      </CardHeader>
      <CardBody>
        <FormGroup row className="my-0">
          <Col xs="12" lg="6">
            <Field
              name="auctionNumber"
              type="text"
              component={FormInput}
              label="Auction Number *"
              normalize={auctionNumber}
            />
          </Col>

【问题讨论】:

    标签: javascript reactjs firebase redux-form


    【解决方案1】:

    这样解决

          componentDidMount() {
        let auctionNumber, auctionAmount;
        this.props.dispatch(fetchAuctionByChitty(chittieId)).then((data) => {
          let currentLength = Object.keys(data).length;
          auctionNumber = currentLength + 1;
          if (auctionNumber <= 20) {
            auctionAmount = this.chitPayment[currentLength].maturityAmount;
            this.props.initialize({
              auctionNumber: auctionNumber,
              auctionAmount: auctionAmount
            });
          }
        });
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多