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
136 views
in Technique[技术] by (71.8m points)

javascript - React Native - Map elements two on a row

I have an array of objects in React Native. What is the simplest way to map them two on a row like in the following picture:

https://i.stack.imgur.com/VGWTr.png

I have a function that converts an array into an array of arrays of 2 elements:

{/* Example input: [0, 1, 2, 3, 4, 5, 6, 7] */}
{/* Example output: [ [0, 1] , [2, 3] , [4, 5] , [6, 7] ] */}

then simply map each element into a View that contains two other View elements, but seems way too overkill.

Is there a simpler method?

question from:https://stackoverflow.com/questions/65601315/react-native-map-elements-two-on-a-row

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

1 Answer

0 votes
by (71.8m points)

yes, there is a simpler way. You could set width 50% to each element and to the parent set flexDirection: 'row' and flexWrap: 'wrap'


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

...