【问题标题】:Is there a way to get the list length for a given database?有没有办法获取给定数据库的列表长度?
【发布时间】:2021-08-08 00:22:34
【问题描述】:

我可以使用https://api.notion.com/v1/databases/:id/query 获取给定数据库的分页子列表。但是我可以在任何地方获取当前的孩子数量吗?

【问题讨论】:

    标签: notion-api


    【解决方案1】:

    该 API 在当前版本的 API(Notion-Version:2021-05-13)中没有提供结果计数。

    【讨论】:

      【解决方案2】:

      如果你想要数据库中的页数(子),假设是javascript。

      <!DOCTYPE html>
      <html>
      
      <body>
      
        <p>Click the button to create an array, then display its length.</p>
      
        <button onclick="myFunction()">Find Length</button>
      
        <p id="demo"></p>
      
        <script>
          function myFunction() {
            var data = {
              "object": "list",
              "results": [{
                  "object": "page",
                  "id": "2e01e904-febd-43a0-ad02-8eedb903a82c",
                  "created_time": "2020-03-17T19:10:04.968Z",
                  "last_edited_time": "2020-03-17T21:49:37.913Z",
                  "parent": {
                    "type": "database_id",
                    "database_id": "897e5a76-ae52-4b48-9fdf-e71f5945d1af"
                  },
                  "archived": false,
                  "properties": {
                    "Recipes": {
                      "id": "Ai`L",
                      "type": "relation",
                      "relation": [{
                          "id": "796659b4-a5d9-4c64-a539-06ac5292779e"
                        },
                        {
                          "id": "79e63318-f85a-4909-aceb-96a724d1021c"
                        }
                      ]
                    },
                    "Cost of next trip": {
                      "id": "R}wl",
                      "type": "formula",
                      "formula": {
                        "type": "number",
                        "number": 2
                      }
                    },
                    "Last ordered": {
                      "id": "UsKi",
                      "type": "date",
                      "date": {
                        "start": "2020-10-07",
                        "end": null
                      }
                    },
                    "In stock": {
                      "id": "{>U;",
                      "type": "checkbox",
                      "checkbox": false
                    }
                  }
                },
                {
                  "object": "page",
                  "id": "2e01e904-febd-43a0-ad02-8eedb903a82c",
                  "created_time": "2020-03-17T19:10:04.968Z",
                  "last_edited_time": "2020-03-17T21:49:37.913Z",
                  "parent": {
                    "type": "database_id",
                    "database_id": "897e5a76-ae52-4b48-9fdf-e71f5945d1af"
                  },
                  "archived": false,
                  "properties": {
                    "Recipes": {
                      "id": "Ai`L",
                      "type": "relation",
                      "relation": [{
                          "id": "796659b4-a5d9-4c64-a539-06ac5292779e"
                        },
                        {
                          "id": "79e63318-f85a-4909-aceb-96a724d1021c"
                        }
                      ]
                    },
                    "Cost of next trip": {
                      "id": "R}wl",
                      "type": "formula",
                      "formula": {
                        "type": "number",
                        "number": 2
                      }
                    },
                    "Last ordered": {
                      "id": "UsKi",
                      "type": "date",
                      "date": {
                        "start": "2020-10-07",
                        "end": null
                      }
                    },
                    "In stock": {
                      "id": "{>U;",
                      "type": "checkbox",
                      "checkbox": false
                    }
                  }
                }
              ],
              "has_more": false,
              "next_cursor": null
            }
            document.getElementById("demo").innerHTML = data.results.length;
          }
        </script>
      
      </body>
      
      </html>

      【讨论】:

      • 这样我必须请求所有内容,然后在我的后端/前端中检查它。 API 在响应中发送的最大结果数为每页 100 个。对于大型数据库,我必须发出多个请求才能检查列表的长度。这似乎非常低效。
      • 不幸的是,Notion 无法轻松返回数据库中的全部项目。
      猜你喜欢
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多