文本不会在 React Native Component 中换行
Text doesn't wrap in React Native Component
所以我正在使用 Flatlist 并使用数组中的数据并将其显示在屏幕上。
这就是我的意思。
我希望我的输出像红色框中显示的那样。
这是我的代码。
_renderItem (item) {
return(
<View style={{ width: 350, flexGrow: 1, }}>
<Text style={{ fontSize: 16, color: 'black', }}>
{item.law_practice_description} , // item.law_practice_description shows me the text like Administrative Adjudications etc
</Text>
</View>
);
}
render() {
return (
<View style={{ flex: 1 }}>
<Text style={styles.titleTxt}>Administrative Law</Text>
<FlatList
style={{ marginTop: 20,}}
data={this.state.data}
renderItem={({item}) => this._renderItem(item) }
keyExtractor={(index) => index.toString()}
/>
</View>
);
}
}
从代码中删除平面列表:
用以下代码替换您的渲染方法:
constructor(props) {
super(props)
this.state = {
data: [{ law_practice_description: 'Administration Administration' },
{ law_practice_description: 'Administration Agency Prctice' },
{ law_practice_description: 'Administration hearing and appeals' },
{ law_practice_description: 'Administration Administration' },
{ law_practice_description: 'Administration Agency Prctice' },
{ law_practice_description: 'Administration hearing and appeals' },
{ law_practice_description: 'Administration Administration' },
{ law_practice_description: 'Administration Agency Prctice' },
{ law_practice_description: 'Administration hearing and appeals' }],
};
}
render() {
let str = ''
this.state.data.map((item, index) => {
if (index == 0) {
str = item.law_practice_description
} else {
str = str + ', ' + item.law_practice_description
}
})
return (
<View style={{ flex: 1 }} >
<Text style={styles.titleTxt}>Administrative Law</Text>
<Text style={{ fontSize: 16, color: 'black', }}>
{str}
</Text>
</ View>
);
}
所以我正在使用 Flatlist 并使用数组中的数据并将其显示在屏幕上。 这就是我的意思。
我希望我的输出像红色框中显示的那样。
这是我的代码。
_renderItem (item) {
return(
<View style={{ width: 350, flexGrow: 1, }}>
<Text style={{ fontSize: 16, color: 'black', }}>
{item.law_practice_description} , // item.law_practice_description shows me the text like Administrative Adjudications etc
</Text>
</View>
);
}
render() {
return (
<View style={{ flex: 1 }}>
<Text style={styles.titleTxt}>Administrative Law</Text>
<FlatList
style={{ marginTop: 20,}}
data={this.state.data}
renderItem={({item}) => this._renderItem(item) }
keyExtractor={(index) => index.toString()}
/>
</View>
);
}
}
从代码中删除平面列表:
用以下代码替换您的渲染方法:
constructor(props) {
super(props)
this.state = {
data: [{ law_practice_description: 'Administration Administration' },
{ law_practice_description: 'Administration Agency Prctice' },
{ law_practice_description: 'Administration hearing and appeals' },
{ law_practice_description: 'Administration Administration' },
{ law_practice_description: 'Administration Agency Prctice' },
{ law_practice_description: 'Administration hearing and appeals' },
{ law_practice_description: 'Administration Administration' },
{ law_practice_description: 'Administration Agency Prctice' },
{ law_practice_description: 'Administration hearing and appeals' }],
};
}
render() {
let str = ''
this.state.data.map((item, index) => {
if (index == 0) {
str = item.law_practice_description
} else {
str = str + ', ' + item.law_practice_description
}
})
return (
<View style={{ flex: 1 }} >
<Text style={styles.titleTxt}>Administrative Law</Text>
<Text style={{ fontSize: 16, color: 'black', }}>
{str}
</Text>
</ View>
);
}