Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在盖茨比+;JS搜索?_Javascript_Reactjs_Lazy Loading_Gatsby_Gatsby Image - Fatal编程技术网

Javascript 在盖茨比+;JS搜索?

Javascript 在盖茨比+;JS搜索?,javascript,reactjs,lazy-loading,gatsby,gatsby-image,Javascript,Reactjs,Lazy Loading,Gatsby,Gatsby Image,我正在使用jssearch搜索盖茨比网站上的一些博客文章。我一直在跟踪 现在,如果我从axios请求中获得一个非常大的数据集,页面上将显示许多博客文章。有没有一种方法可以让我在这里为这些博客文章设置延迟加载,同时仍然能够通过盖茨比搜索所有这些文章?或者至少懒洋洋地加载我得到的图像(我将得到一个指向JSON中图像的链接)?我认为解决问题的最佳方法是通过编程实现。在ClientSearchTemplate组件中,您可以通过道具获得所有书籍。只要在里面写上逻辑和状态,记住页面和页面上的项目数,在从一页

我正在使用
jssearch
搜索盖茨比网站上的一些博客文章。我一直在跟踪


现在,如果我从axios请求中获得一个非常大的数据集,页面上将显示许多博客文章。有没有一种方法可以让我在这里为这些博客文章设置延迟加载,同时仍然能够通过盖茨比搜索所有这些文章?或者至少懒洋洋地加载我得到的图像(我将得到一个指向JSON中图像的链接)?

我认为解决问题的最佳方法是通过编程实现。在ClientSearchTemplate组件中,您可以通过道具获得所有书籍。只要在里面写上逻辑和状态,记住页面和页面上的项目数,在从一页到另一页的过程中切分一些书。

作为评论而不是完整的解决方案来回答是有意义的。嗨,我刚刚看到这个问题,你找到解决方案了吗?我需要为我正在进行的项目实现类似的功能,我认为解决方案是在搜索结果中添加分页,然后在客户端延迟加载它们。如果不晚,我会设法赶过去。让我知道
const path = require("path")
const axios = require("axios")
exports.createPages = ({ actions }) => {
  const { createPage } = actions
  return new Promise((resolve, reject) => {
    axios
      .get("https://bvaughn.github.io/js-search/books.json")
      .then(result => {
        const { data } = result
        /**
         * creates a dynamic page with the data received
         * injects the data into the context object alongside with some options
         * to configure js-search
         */
        createPage({
          path: "/search",
          component: path.resolve(`./src/templates/ClientSearchTemplate.js`),
          context: {
            bookData: {
              allBooks: data.books,
              options: {
                indexStrategy: "Prefix match",
                searchSanitizer: "Lower Case",
                TitleIndex: true,
                AuthorIndex: true,
                SearchByTerm: true,
              },
            },
          },
        })
        resolve()
      })
      .catch(err => {
        console.log("====================================")
        console.log(`error creating Page:${err}`)
        console.log("====================================")
        reject(new Error(`error on page creation:\n${err}`))
      })
  })
}