コンポーネントのレンダリング機能で、子コンポーネントを読み込み中に折り返しdivが生成されるという問題があります。私は、グリッドのためのブートストラップのフレームワークを使用しています反応React jsが折り返しを避ける
renderFields = (obj) =>{
let des = translate(obj.description);
let mandatory = (obj.required == true) ? " *" : ""
let description = des + mandatory;
if(obj.variable){
switch(obj.dataType){
case "string":
return ([
<Col xs={12} md={3}>
<TextField fullWidth={true} ref={obj.code} floatingLabelText={description} value={this.props.value} onChange={(e,newValue) => this.props.handler(newValue, obj.code, obj.required, '')} errorText={this.props.error ? this.props.error : ""}/>
</Col>]
);
case "integer":
return (
<Col xs={12} md={3}>
<TextField fullWidth={true} ref={obj.code} floatingLabelText={description} value={this.props.value} onChange={(e,newValue) => this.props.handler(newValue, obj.code, obj.required, /^[+-]?\d+$/)} errorText={this.props.error ? this.props.error : ""} />
</Col>
);
case "double":
return (
<Col xs={12} md={3}>
<TextField fullWidth={true} ref={obj.code} floatingLabelText={description} value={this.props.value} onChange={(e,newValue) => this.props.handler(newValue, obj.code, obj.required, /^[+-]?\d+(\.\d+)?$/)} errorText={this.props.error ? this.props.error : ""}/>
</Col>
);
}
}
}
render(){
return (
<div>
{this.renderFields(this.props.obj)}
</div>
);
}
:
render(){
return(
<Card style={styles.cardStyle}>
{this.getTitle(this.props.name, this.props.constraint)}
<CardText>
<Grid fluid={true}>
<Row>
<Fields key={0} obj={this.props.fields[0]} value={""} error={""} handler={this.props.handler}></Fields>
</Row>
</Grid>
</CardText>
</Card>
)
}
子コンポーネント機能:コンポーネントの機能をレンダリング
親。私は多くの解決策を試しましたが、残念なことに私のために働かなかったのです。それは子コンポーネント(フィールド)の前に折り返しdivを生成しています。出力は以下のようになります。
私はこの問題を把握助けて!私は反応するのが新しい。
divの子の出力を明示的に折り返して表示するので、何を期待しましたか?あなたは 'return this.renderFields(this.props.obj)'をちょうど実行できませんか? – Valentin
React 16はラッパー要素を必要としないことに注意してくださいhttps://github.com/facebook/react/issues/2127#issuecomment-318202889 – Valentin