Ich bekomme diese JSON-Antwort von API in React Native.Requisiten auf jeden Bildschirm verteilen
[
{
"cloth_image": "https://ox0%3es",
"id": 7,
"big_cloth_type": "t"
},
{
"cloth_image": "https://qM%3D&",
"id": 8,
"big_cloth_type": "t"
},
{
"cloth_image": "https://qM%",
"id": 9,
"big_cloth_type": "o"
},
{
"cloth_image": "https://qD&",
"id": 10,
"big_cloth_type": "s"
}
]
Diese obige Antwort wird als this.props.clothesList von Redux gespeichert.
Was ich tun möchte, ist, wenn die Objekte von big_cloth_type
im Array t
ist, möchte ich sie dem entsprechenden Bildschirm zuweisen. (In diesem Fall ist es TopScreen)
Von Code (Dies ist render() Funktion)
<View style={{flex: 1}}>
<Tabs initialPage={0}>
<Tab heading={<TabHeading><Text style={styles.tabHeadingStyle}>Tops</Text></TabHeading>}>
<TopScreen clothes={blahblah}/> <----- here I want to pass objects with 't' type to this Screen.
</Tab>
<Tab heading={<TabHeading><Text style={styles.tabHeadingStyle}>Outers</Text></TabHeading>}>
<OutwearScreen clothes={blahblah} /> <--- here the objects with 'o'
</Tab>
<Tab heading={<TabHeading><Text style={styles.tabHeadingStyle}>Bottoms</Text></TabHeading>}>
<BottomScreen />
</Tab>
<Tab heading={<TabHeading><Text style={styles.tabHeadingStyle}>Shoes</Text></TabHeading>}>
<ShoeScreen />
</Tab>
<Tab heading={<TabHeading><Text style={styles.tabHeadingStyle}>ETC</Text></TabHeading>}>
<EtcScreen />
</Tab>
</Tabs>
<FABs
active={this.state.active}
/>
</View>
ich nicht mit einer Lösung aufwarten kann so weit. :(
Für den Vorschlag des Kommentars, ich bin Entsendung meine Minderer
export default function(state = INITIAL_STATE, action) {
switch (action.type) {
case CLOTHES_LIST_SUCCESS:
return { ...state, clothesList: action.payload }
case CLOTHES_LIST_FAIL:
return { ...state, }
default:
return state;
}
}
Wenn du redux verwendest, wird es nicht einfacher sein, es in den Behältern zu filtern und es als neue Stütze an die Komponenten weiterzugeben? – semuzaboi
@luciferous Das klingt großartig! Ich habe gerade meinen Reducer gepostet. Ist die Performance besser, wenn ich "Requisiten", "Tops", "Outwear" etc. anstelle von Requisiten verwende? Was kann der Vorteil sein, das zu tun? –