[英]How to get button title?
Im trying to get my button name, from the event, but I'm not finding it我试图从事件中获取我的按钮名称,但我没有找到它
my button call(JSX) code:我的按钮调用(JSX)代码:
{...}
<View style={styles.container}>
{userForm.map((item) => (
<Button title = {item.name.slice(7)} key = {item.info.uuid} onPress = {handleClick} />
))}
</View>
{...}
My handle click constant where I try to get the button title:我尝试获取按钮标题的句柄单击常量:
const handleClick = (e) => {
var objeto = e.currentTarget.title;
console.log(objeto);
};
someone knows where or how to get my button title?有人知道在哪里或如何获得我的按钮标题吗?
e.currentTarget
gives you the button element that is rendered in your screen. e.currentTarget
为您提供在屏幕中呈现的按钮元素。 You could access its text content by using e.currentTarget.textContent
or you can pass the title as an argument directly to your handleClick
function:您可以使用e.currentTarget.textContent
访问其文本内容,也可以将标题作为参数直接传递给您的handleClick
function:
<Button title = {item.name.slice(7)} key = {item.info.uuid} onPress = {handleClick(item.name.slice(7))} />
const handleClick = (buttonTitle) => (e) => {
console.log(buttonTitle)
};
Try changing your objeto
to var objeto = e.currentTarget.title;
尝试将您的objeto
更改为var objeto = e.currentTarget.title;
You're setting title
on the component but trying to read name
on your handleClick.您正在组件上设置title
,但试图在您的 handleClick 上读取name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.