【发布时间】:2019-07-17 23:39:43
【问题描述】:
我对 PouchDB 的数组值有疑问。
在我的数据库文档中:
"ExercisesData": [
{
"Id": "01",
"Reps": "10",
"StartDate": "2019-06-20",
"EndDate": "2019-06-21",
"Notes": ".........."
},
{
"Id": "02",
"Reps": "1",
"Notes": "........"
},
{
"Id": "03",
"Reps": "150",
"Notes": "........"
}
]
我需要打印这些值,然后让用户选择其中一个值 (Id)。
我尝试以这种方式从数据库中获取这些值:
findUtente(cf) {
let params = {};
params = {
"Person.FiscalCode": cf
};
global.utente.db.localdb().find({
selector: {params},
})
.then(response => {
let utente = response.docs[0];
console.log(utente);
this.setState({ Id: utente.ExercisesData.Id })
console.log("utente.ExercisesData.Id: " + utente.ExercisesData.Id)
})
.catch(function(err) {
console.log(JSON.stringify(err));
});
}
render() {
console.log("this.state.Id: " + this.state.Id)
return(
<View>
<Text>{this.state.Id}</Text>
</View>
);
}
但是这段代码在 catch 中,给我返回错误:{} 问题应该是我试图以错误的方式获取元素。也许我应该使用 .Map 参数? 如何恢复这些值并将它们打印在页面中?谢谢。
【问题讨论】:
-
没人能帮我吗??
标签: javascript react-native pouchdb