React native 如何在函数中使用id更改组件值或类似文本的颜色?
我想更改文本组件值,但我不想使用state,因为我的文本或其他组件是唯一的,它们通过循环生成,结果来自PHP和MySQLReact native 如何在函数中使用id更改组件值或类似文本的颜色?,react-native,React Native,我想更改文本组件值,但我不想使用state,因为我的文本或其他组件是唯一的,它们通过循环生成,结果来自PHP和MySQL `import React, { Component } from 'react'; import { StyleSheet, View, Text, Button, ToastAndroid } from 'react-native'; class MyAppList extends Component { UserOrderBasket = (ProductId)=&g
`import React, { Component } from 'react';
import { StyleSheet, View, Text, Button, ToastAndroid } from 'react-native';
class MyAppList extends Component {
UserOrderBasket = (ProductId)=>{}
render() {
return (
<View style={{ flex:1, flexDirection: 'row' }}>
<Text id='amir' style={{ flex:0, width:40, textAlign:'center' }}>
this text will be change
</Text>
<Button icon transparent style={{width:36,padding:0}} onPress=
{this.UserOrderBasket.bind(this,1)}>
<Text>Change Text</Text>
</Button>
</View>
)
}
}
`
`
有可能吗???
如果我真的需要,请帮助我。这是可行的,但不是React推荐的方法。在react中,虚拟DOM被广泛使用,而对于您的情况,您直接使用DOM
推荐的方法仍然是使用状态/道具作为媒介。函数的作用是:更改状态,文本会自动更新 在以下链接中,您可以找到React的状态和生命周期系统:只需了解有关您给出的状态提示的更多详细信息:)
function UserOrderBasket (ProductId){
document.getElementById('amir').inneHtml="some text or elemnt put here";
}