Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

antd Upload放动态增减表单 onchange不起作用是什么原因

如标题 发现上传有去调用接口 但是没有调用onChange方法 代码如下

getFieldDecorator('keys', { initialValue: [0] });
          const keys = getFieldValue('keys');
          const formItems = keys.map((k, index) => (
            <Row key={k} gutter={24} style={{border: "1px dashed rgba(0,0,0,0.3)", alignItems: 'center', display: 'flex', flexDirection: 'row', marginBottom: 30}}>
              <Col span={6}>
                <Form.Item
                  key={k}
                  style={{margin: 0}}
                >
                  {getFieldDecorator(`pname[${k}]`, {
                    initialValue: pname[k],
                    rules: [{
                      required: true,
                      whitespace: true,
                      message: "请输入产品名称/标题",
                    }],
                  })(
                    <Input placeholder="产品名称/标题"/>
                  )}
                </Form.Item>
              </Col>
              <Col span={16}>
                <Form.Item style={{margin: 0, marginTop: 25}}>
                  {getFieldDecorator(`pres[${k}]`, {
                    initialValue: fileList && fileList[k] && fileList[k].length > 0 ?  fileList[k] : [],
                    rules: [{
                      required: true,
                      message: "请上传资料类型",
                    }],
                  })(
                    <Upload
                      key={"upload" + k}
                      action={upload}
                      fileList={fileList && fileList[k] && fileList[k].length > 0 ?  fileList[k] : []}
                      onChange={(e) => {this.handleChange(e,k)}}
                      listType="picture-card"
                    >
                      {uploadButton}
                    </Upload>
                  )}
                </Form.Item>
              </Col>
              <Col span={2}>
                  {keys.length > 1 ? (
                    <Icon
                      style={{ marginLeft: 8 }}
                      className="dynamic-delete-button"
                      type="minus-circle-o"
                      onClick={() => this.remove(k)}
                    />
                  ) : null}
              </Col>
            </Row>
          ));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Form.Item下的onChange是自动注入的 你要自定义的话就要把Upload再封一层


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...