Javascript 如何使用带有JSX元素的for循环将集合内容打印到多个<;文本>;在React Native中的标记?
基本上,我希望在React Native render()中实现以下拓扑: 有人能告诉我如何在React Native中实现这一点吗?Javascript 如何使用带有JSX元素的for循环将集合内容打印到多个<;文本>;在React Native中的标记?,javascript,for-loop,react-native,jsx,Javascript,For Loop,React Native,Jsx,基本上,我希望在React Native render()中实现以下拓扑: 有人能告诉我如何在React Native中实现这一点吗?renderItem(){ renderItem() { const list = [ { price: '5,000', text: 'April stay also', }, { price: '6,000', text: 'May stay also', }, ]
renderItem(){
renderItem() {
const list = [
{
price: '5,000',
text: 'April stay also',
},
{
price: '6,000',
text: 'May stay also',
},
]
return (
<View>
{list.map((val, key) =>
<View key={key} >
<Text>{val.price}</Text>
<Text>{val.text}</Text>
</View>
)}
</View>
);
}
常数列表=[
{
价格:'5000',
文字:“四月也住”,
},
{
价格:'6000',
文字:“也可以留下来”,
},
]
返回(
{list.map((val,key)=>
{val.price}
{val.text}
)}
);
}
使用:
{this.renderItem()}
collectionToView(collection, keys)
{
let rows = [];
for (key in keys)
{
rows.push(<Text> key + ": " + collection[key] </Text>);
}
return rows;
}
<View>
{this.collectionToView(userData, {'serial','product_id','product_name','status'})}
</View>
renderItem() {
const list = [
{
price: '5,000',
text: 'April stay also',
},
{
price: '6,000',
text: 'May stay also',
},
]
return (
<View>
{list.map((val, key) =>
<View key={key} >
<Text>{val.price}</Text>
<Text>{val.text}</Text>
</View>
)}
</View>
);
}
<View>
{this.renderItem()}
</View>