亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在反應本機中按下字段時過濾項目

在反應本機中按下字段時過濾項目

泛舟湖上清波郎朗 2022-10-13 15:39:35
我有一個帶有不同卡片的屏幕(有文章信息)我試圖在按下方便的類別時按類別過濾文章我希望選擇該類別并顯示屬于該類別的文章,另一方面當沒有選擇任何類別時,將所有類別中的所有文章都交給顯示(如果您看下面的圖片,這將更有意義)用于顯示不同類別圖片的代碼:import TouchableScale from "react-native-touchable-scale";import { category } from "../api/data";import colors from "../config/colors";function HotTopics({ navigation }) {  //const { width, height } = Dimensions.get("window");  return (    <View style={styles.Container}>      <View>        <Text style={styles.CategoryText}>Hot Topics</Text>      </View>      <FlatList        horizontal        showsHorizontalScrollIndicator={false}        style={{ paddingHorizontal: 15 }}        data={category}        keyExtractor={(item) => item.id}        renderItem={({ item }) => {          return (            <View>              <View>                <TouchableScale                  activeScale={0.9}                  tension={50}                  friction={7}                  useNativeDriver                  onPress={() => navigation.navigate({ id: item.id })}                >                  {/* to show the horizental news list*/}                  <Image                    source={{ uri: item.image }}                    style={{                      width: 100,                      height: 120,                      borderRadius: 16,                      marginRight: 10,                    }}                  />                  {/* to show the news titles inside the pictures*/}                  <SharedElement                    id={`item.${item.id}.text`}                    style={{                      width: 100,                      position: "absolute",                      bottom: 95,                      //left: 10,                      paddingHorizontal: 5,                      justifyContent: "center",                      alignItems: "center",                    }}       
查看完整描述

1 回答

?
嗶嗶one

TA貢獻1854條經驗 獲得超8個贊

處理這個問題的最簡單方法是有一個回調函數來設置 HotTopics 組件的狀態,如下所示

const [category, setCategory] = useState();

在渲染中

  <HotTopics onCategorySelect={setCategory} /> 
   <ArticleListVer post={filterResultsByCategory(category)} />

對于熱門話題的點擊,你可以做

onPress={() =>
            this.props.onCategorySelect(item.category)
          }

通過這樣做,您將使用新類別重新呈現父級。對于重置,您需要一個按鈕將狀態重置為空,以便顯示所有項目。


查看完整回答
反對 回復 2022-10-13
  • 1 回答
  • 0 關注
  • 88 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號