我想在我的應用程序上顯示膳食'標籤'列表。所以根據下面的代碼,我能夠做到這一點。所以作爲代碼的結果,我會得到一個列表或一組顯示的mealTags。如何隱藏JSX中的某些元素
問題:我想只顯示前2個標籤,隱藏其餘標籤並放置一個鏈接'顯示更多,其餘部分在我點擊它時出現。我如何在ReactJS中執行此操作?
return (
<View {...otherprops} style={styles.mainContainer} elevation={3}>
<View style={styles.contentContainer}>
<MealTagsSection mealTags={post.mealTags} />
</View>
type MealTagsProps = {
mealTags: Array<MealTag>;
};
export function MealTagsSection(props: MealTagsProps) {
let {mealTags} = props;
return (
<View style={styles.mealTagsContainer}>
{
mealTags.map((mealTag) => {
let tagStyle = '';
if (mealTag.category === 1) {
tagStyle = styles.tag_healthy;
} else {
tagStyle = styles.tag_improve;
}
return (
<View style={tagStyle}>
<Text style={styles.tagText}>{mealTag.description}</Text>
</View>
);
})
}
</View>
);
}
謝謝@Ahbishek。只有存在隱藏標籤時,我是否也可以獲得有關如何檢查並顯示「加載更多」鏈接的建議?我可以做這個膳食標籤切割功能嗎? – Zhen
你可以在加入更多鏈接前檢查放置一個標誌,'{this.state.visibleCount } –
Abhishek