简体   繁体   English

PouchDB采用数组值

[英]PouchDB take array values

I have a problem with PouchDB with array values. 我对带有数组值的PouchDB有问题。

In my document on the DB I have: 在数据库上的文档中,我有:

"ExercisesData": [
        {
          "Id": "01",
          "Reps": "10",
          "StartDate": "2019-06-20",
          "EndDate": "2019-06-21",
          "Notes": ".........."
        },
        {
          "Id": "02",
          "Reps": "1",
          "Notes": "........"
        },
        {
          "Id": "03",
          "Reps": "150",
          "Notes": "........"
        }
  ]

I need to print this values, and let choose one of these values (Id) at the user. 我需要打印此值,然后让用户选择这些值(Id)之一。

I've tried to take this values from the db in this way: 我试图以这种方式从数据库中获取此值:

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>
            );
          }

But this code go in the catch, give me back the error: {} The problem should be that I'm trying to take the elements in wrong way. 但是这段代码很重要,将错误传给我:{}问题应该是我试图以错误的方式处理元素。 Maybe I should use the .Map param ? 也许我应该使用.Map参数? How can I do to recover these value and print them in a page? 如何恢复这些值并将其打印在页面中? Thank you. 谢谢。

I have solved in this way: 我已经用这种方式解决了:

 const exercises = this.state.Exercises.map(exercise => {
      return (
        <View>
          <Text style={{ fontSize: 15 }}> {exercise.Id}</Text>
          <Text style={{ fontSize: 15 }}> {exercise.Reps}</Text>
          <Text style={{ fontSize: 15 }}> {exercise.Notes}</Text>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM