我有一个关于如何在函数中打印值的问题,在 react-native 中。
基本上我有一个函数可以在数据库中研究一些值,我应该打印这些值。
findUtente(cf) {
let params = {};
console.log(cf)
params = {
"Person.FiscalCode": cf
};
global.utente.db.localdb().find({
selector: params
})
.then(response => {
let utente = response.docs[0];
console.log ("utente: " + utente)
utente.Person.FirstName;
console.log ("utente.Person.FirstName: " + utente.Person.FirstName)
})
//.... catch...}); }
render() {
{this.findUtente(this.props.cf)}
return (
<View style={style.container}>
<View style={style.page}>
<KeyboardAwareScrollView>
<Text style={visualProfilo.text}>Name:</Text>
<Text style={visualProfilo.text1}>{Stamp Here the FirstName}</Text>
控制台日志中的值以正确的方式打印。 如何打印该值?
谢谢
最佳答案
您可以使用 componentDidMount
调用该方法,然后您可以将值设置为状态,然后使用 setState 更新值,然后呈现状态值
示例:
state = {
FirstName: ''
}
componentDidMount(){
this.findUtente(this.props.cf)
}
findUtente(cf) {
let params = {};
console.log(cf)
params = {
"Person.FiscalCode": cf
};
global.utente.db.localdb().find({
selector: params
})
.then(response => {
let utente = response.docs[0];
this.setState({FirstName: utente.Person.FirstName})
})
//.... catch...}); }
render() {
return (
//everything remains same
<Text style={visualProfilo.text1}>{this.state.FirstName}</Text>
)
}
关于javascript - 从函数打印值。 react native ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56854315/