javascript - 从数据库更新值。反应原生
问题描述
我需要从数据库(couchdb/pouchdb)更新一些值。
我有这个结构:身份验证页面 StartingConsumer(我在其中检查用户是否已登录)如果用户已登录,他将被重定向到 HomepageUtente。
在 HomepageUser 中,我有 FirstName 和 LastName 变量,还有一个文本“Modifica Profilo”来更改 pouchdb 中的一些值。
现在的问题是,如果我通过“Modifica Profilo”更改值,则 HomepageUser 中的值(名字和姓氏不会改变)。
我已经评论了我之前使用的代码。
使用新代码时,我遇到的问题是没有任何变化,因此值“FirstName”和“LastName”不会改变。
您认为错误在哪里?谢谢你。
启动Consumer.js
class StartingConsumer extends Component {
constructor(props) {
super(props);
this.state = {
loading: true
};
}
componentWillMount() {
Utente.getUtenteLoggato()
.then(dataUtenteLoggato => {
if (dataUtenteLoggato !== null) {
global.utente = new Utente(JSON.parse(dataUtenteLoggato));
//Actions.homepageutente()({ type: "reset" });
Actions.homepageutente({ utente: global.utente });
} else {
Actions.loginconsumer();
}
})
.catch(err => {
console.log(err);
})
.finally(() => {
this.setState({ loading: false });
});
}
主页Utente
class HomepageUtente extends Component {
constructor(props) {
super(props);
}
render() {
const utentelogged = this.props.utente;
console.log("Utente Logged" + utentelogged)
//const FirstName = global.utente.data.Person.FirstName;
const FirstName = utentelogged.data.Person.FirstName;
//const LastName = global.utente.data.Person.LastName;
const LastName = utentelogged.data.Person.LastName;
//const Username = global.utente.data.Person.FiscalCode;
const Username = utentelogged.data.Person.FiscalCode;
//const Roles = global.utente.data.Person.Roles
const Roles = utentelogged.data.Roles
return (
<View style={style.container}>
<View style={style.page}>
<Icon name="user-circle" color="#64c7c0" size={70} onPress={() => Actions.visualizzaprofilo({ cf: Username } )} />
<Text
style={{ paddingBottom: 15, textAlign: 'center', fontSize: 15, color: '#64c7c0', fontWeight: 'bold' }}
onPress={() => Actions.visualizzaprofilo({ cf: Username } )} >Visualizza il Profilo
</Text>
<Text
style={{ textAlign: 'center', fontSize: 20, }}>{"Benvenuto"}
</Text>
<Text
style={{ textAlign: 'center', fontSize: 20, color: '#64c7c0', fontWeight: 'bold' }}>
{FirstName} {LastName}
</Text>
<Text
style={{ color: '#64c7c0', paddingTop: 20 }}
onPress={() => Actions.modificaprofilo({ cf: Username })} >MODIFICA PROFILO</Text>}
ModificaProfilo.js
export default class ModificaProfilo extends Component {
constructor(props) {
super(props);
this.state = {
/* firstName: "",
lastName: "",
dateOfBirth: "",
address: "",
city: "",
country: "",
email: "",
height: "",
weight: "",
shoesModel: ""*/
};
}
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];
utente.Person.FirstName = this.state.FirstName;
utente.Person.LastName = this.state.LastName;
utente.Person.City = this.state.City;
utente.Person.Address = this.state.Address;
console.log("utente" + utente)
return global.utente.db.localdb().put(utente);
解决方案
推荐阅读
- c++ - 用 C++ 包装一个 C 插件
- python - 如何在条件下替换数据框的值
- java - Java二叉搜索树方法需要返回值而不是打印
- amazon-web-services - 使用 AWS Fargate 运行服务时出现“网络绑定 - 未配置”
- python - 如何规范 scikit learn 的 kde?
- javascript - Fullcalendar - 无法在月视图中显示日期名称
- json - 如何在 Microsoft Flow 中转义 json 中的引号?
- javascript - 尝试使用 try 和 catch 作为条件
- python - 是否可以将 HyperDriveStep 与时间序列交叉验证一起使用?
- python - 使用正则表达式忽略不完整的数据集?