[英]How to generate dynamic UI on the basis of array value in react-native
I am trying to generate dynamic UI according to array value.我正在尝试根据数组值生成动态 UI。 formfiled is array were am getting below value. formfiled 是数组正在低于值。 I have to generate dynamic ui according to below response.我必须根据以下响应生成动态 ui。 Now here at index 2 State of Origin
is coming at 3 LGA of Origin
.现在在索引 2 State of Origin
即将到达 3 LGA of Origin
。 I have to reverse this.我必须扭转这一点。 I mean rest anything should come as it.我的意思是 rest 任何事情都应该如此。 But I have to display "LGA of Origin"
first and below after that "State of origin"
.但是我必须在"LGA of Origin"
"State of origin"
。 I can't give array index because it may change.我不能给出数组索引,因为它可能会改变。 Please help请帮忙
// formfield array value is below // formfield数组值在下面
formfiled
0:
key: "dateOfBirth"
label: "Date of Birth"
model: "model.dateOfBirth"
name: "dateOfBirth"
placeHolder: "DD/MM/YYYY"
position: "1"
required: "true"
type: "date"
__typename: "FormFields"
__proto__: Object
1:
key: "lastRechargedAmount"
label: "Last RCC Amt."
model: "model.lastRechargedAmount"
name: "lastRechargedAmount"
placeHolder: "Amount in Naira"
position: "2"
required: "false"
type: "text"
__typename: "FormFields"
__proto__: Object
2:
key: "stateOfOrigin"
label: "State of Origin"
model: "model.stateOfOrigin"
name: "stateOfOrigin"
placeHolder: "State of origin"
position: "3"
required: "true"
type: "parentSelect"
__typename: "FormFields"
__proto__: Object
3:
key: "lgaOfOrigin"
label: "LGA of Origin"
model: "model.lgaOfOrigin"
name: "lgaOfOrigin"
placeHolder: "Enter Lga of origin"
position: "4"
required: "true"
type: "childSelect"
__typename: "FormFields"
<View style={styles.container}>
{formFields.map((document, index) => {
return (
<View style={{flexDirection: 'column', backgroundColor: '#fff', padding: 15}}
key={index}>
{document.type==='text' && (
<View style={{ }}>
<View style={{ flexDirection: 'row', backgroundColor: '#fff'}}>
<SmallText textColor="grey" text={document.label} />
</View>
<Item style={{ borderColor: '#00fff', borderBottomWidth: 1, marginLeft: 0 }}>
<Input
value={lastName}
keyboardType='default'
onChangeText={(lastName) =>
this.setState({ lastName: lastName.replace(/\s/g, '') })}
/>
</Item>
</View>
)
}
{document.type === 'parentSelect' && (
<View style={{flexDirection:'row'}}>
<SelectField options={stateOptions} value={statesValue}
onChange={this.selectedDocument} that={this}
label={document.label}/>
</View>
)}
{document.type === 'childSelect' && (
<View style={{ }}>
<View style={{ flexDirection: 'row', backgroundColor: '#fff'}}>
<SmallText textColor="grey" text={document.label} />
</View>
<Item style={{ borderColor: '#00fff', borderBottomWidth: 1, marginLeft: 0 }}>
<Input
value={lgaValue}
keyboardType='default'
onChangeText={(lgaValue) =>
this.setState({ lgaValue: lgaValue.replace(/\s/g, '') })}
/>
</Item>
</View>
)
}
{document.type ==='date' && (
<View >
<View style={{
flexDirection: 'row', backgroundColor: '#fff'
}}>
<SmallText textColor="grey" text={document.label} />
</View>
<Item style={{ borderColor: '#00fff', borderBottomWidth: 1, marginLeft: 0 }}>
<DatePicker
minDate={minDate}
maxDate={currentDate}
currentDate={dateOfBirth}
format={format}
width={deviceWidth}
onChange={(dateOfBirth) => this.onChange(dateOfBirth)}
marginLeft={0}
/>
</Item>
</View>
)}
</View>
);
}
)}
</View>
You can map this array to render your UI or use flatlist and pass this data as datasource to get dynamic UI您可以 map 这个数组来呈现您的 UI 或使用 flatlist 并将此数据作为数据源传递以获取动态 UI
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.