簡體   English   中英

PouchDB采用數組值

[英]PouchDB take array values

我對帶有數組值的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>
            );
          }

但是這段代碼很重要,將錯誤傳給我:{}問題應該是我試圖以錯誤的方式處理元素。 也許我應該使用.Map參數? 如何恢復這些值並將其打印在頁面中? 謝謝。

我已經用這種方式解決了:

 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