gpt4 book ai didi

javascript - 使用 React Native 进行基于标签的过滤

转载 作者:行者123 更新时间:2023-11-29 18:15:39 26 4
gpt4 key购买 nike

这是我的问题。

当我按下 2 个按钮时,我希望这两个按钮的值成为 2 个“标签”,用于使用 React Native 从 mysql 数据库过滤和获取数据。我应该使用 <Button><TouchableOpacity><TouchableHighlight>或任何其他使其发挥作用?

我将如何实现这个?我需要一个示例代码。谢谢!

最佳答案

所有三个组件(ButtonTouchableOpacityTouchableHighlight)均可用于此目的。它们都有 onPress 属性,可以在用户按下交互时触发函数。使用哪一种主要取决于您对设计和实现的偏好。

示例

_onPress = (value) => {
console.log(value); // Do something with the value
}

render() {
return (
<View>
<Button onPress={() => this._onPress('Some Button Value')} title="Press Me!" />
<TouchableOpacity onPress={() => this._onPress('Some TouchableOpacity Value')}>
<Text>{'Press Me!'}</Text>
</TouchableOpacity>
<TouchableHighlight onPress={() => this._onPress('Some TouchableHighlight Value')}>
<Text>{'Press Me!'}</Text>
</TouchableHighlight>
</View>
)
}

关于javascript - 使用 React Native 进行基于标签的过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47050884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com