{"id":3628,"date":"2024-11-10T09:40:37","date_gmt":"2024-11-10T01:40:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3628\/"},"modified":"2024-11-10T09:40:37","modified_gmt":"2024-11-10T01:40:37","slug":"%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e7%82%b9%e5%87%bb%e6%8c%89%e9%92%ae%e5%bc%b9%e7%aa%97%e3%80%81%e5%8a%a0%e8%bd%bd%e5%88%86%e7%b1%bb%e6%95%b0%e6%8d%ae%e5%b9%b6%e6%bb%9a%e5%8a%a8%e7%bf%bb%e9%a1%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3628\/","title":{"rendered":"\u5982\u4f55\u5b9e\u73b0\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173107482372591.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5b9e\u73b0\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5b9e\u73b0\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5bf9\u5e94\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u5b9a\u4e49\u53d8\u91cf\u8bb0\u5f55\u72b6\u6001<\/strong><\/p>\n<p>\u5b9a\u4e49\u53d8\u91cf\u6765\u8bb0\u5f55\u5f53\u524d\u5206\u7c7bID\u3001\u5f53\u524d\u9875\u7801\u548c\u603b\u9875\u6570\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u52a0\u8f7d\u6570\u636e\u51fd\u6570<\/strong><\/p>\n<p>\u521b\u5efa\u51fd\u6570\uff0c\u7528\u4e8e\u52a0\u8f7d\u6307\u5b9a\u5206\u7c7bID\u3001\u9875\u7801\u7684\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6eda\u52a8\u4e8b\u4ef6\u76d1\u542c<\/strong><\/p>\n<p>\u5728\u5185\u5bb9\u533a\u57df\u6dfb\u52a0\u6eda\u52a8\u4e8b\u4ef6\u76d1\u542c\uff0c\u5f53\u6eda\u52a8\u5230\u5e95\u90e8\u65f6\uff0c\u89e6\u53d1\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p><strong>API \u8bf7\u6c42<\/strong><\/p>\n<p>\u4f7f\u7528 API \u8bf7\u6c42\u52a0\u8f7d\u6570\u636e\uff0c\u5e76\u5c06\u8fd4\u56de\u7684\u6570\u636e\u8ffd\u52a0\u5230\u5185\u5bb9\u533a\u57df\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u76d1\u542c<\/strong><\/p>\n<p>\u76d1\u542c\u6309\u94ae\u548c\u9009\u9879\u5361\u7684\u70b9\u51fb\u4e8b\u4ef6\uff0c\u66f4\u65b0\u5206\u7c7bID\u548c\u9875\u7801\uff0c\u5e76\u52a0\u8f7d\u6570\u636e\u3002<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong><\/p>\n<pre>\/\/ \u4e0d\u9700\u8981\u603b\u9875\u6570\uff0c\u56e0\u4e3a\u603b\u9875\u6570\u662f\u540e\u7aef\u8fd4\u56de\u7684\uff0c\u524d\u7aef\u4e0d\u9700\u8981\u77e5\u9053\u603b\u9875\u6570\uff0c\u53ea\u9700\u8981\u77e5\u9053\u5f53\u524d\u9875\u7801\u5373\u53ef\nlet categoryId = 1, currentPage = 1, total = 0;\nlet isLoading = false;\n\n$(document).on('click', '.btn', function () {\n  loadCategoryData(categoryId, currentPage);\n})\n\n$('.tab_p p').click(function () {\n  currentPage = 1;\n  categoryId = $(this).data('id');\n  \/\/ \u52a0\u8f7d\u5bf9\u5e94\u5206\u7c7b\u7684\u6570\u636e\n  loadCategoryData(categoryId, currentPage);\n})\n\nfunction loadCategoryData(id, page) {\n  $(\".tab_item\").html('\u52a0\u8f7d\u4e2d...');\n  $(this).addClass('cur').siblings().removeClass('cur');\n  loadPageData(id, page);\n}\n\n\/\/ \u76d1\u542c\u6eda\u52a8\u4e8b\u4ef6\n$('.tab_item').scroll(function () {\n  console.log('scroll...', $('.tab_item').scrollTop(), $('.tab_item').innerHeight())\n  if (isLoading) {\n    return;\n  }\n  \/\/  \u5224\u65ad\u662f\u5426\u6eda\u52a8\u5230\u5e95\u90e8\u8ddd\u79bb150px \u52a0\u8f7d\u66f4\u591a\n  const scrollTop = $(this).scrollTop();\n  const scrollHeight = $(this).prop('scrollHeight');\n  const containerHeight = $(this).outerHeight();\n\n  if (scrollHeight - scrollTop - containerHeight &lt; 150) {\n    \/\/ \u6eda\u52a8\u5230\u5e95\u90e8\u8ddd\u79bb\u5c0f\u4e8e150px\uff0c\u52a0\u8f7d\u66f4\u591a\u6570\u636e\n    currentPage++;\n    if (currentPage &lt;= total) {\n      loadPageData(categoryId, currentPage);\n    }\n  }\n\n});\n\n\/\/ \u6a21\u62df\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u52a0\u8f7d\u67d0\u4e00\u9875\u7684\u6570\u636e\nfunction getData(categoryId, page) {\n  console.log('getData...', categoryId, page)\n  return new Promise((resolve, reject) =&gt; {\n    setTimeout(() =&gt; {\n      \/\/ \u968f\u673a\u8fd4\u56depage\u6761\u6570\u636e\n      const list = [];\n      \/\/ \u6bcf\u6b21\u8fd4\u56de20\u6761\u6570\u636e\n      for (var i = 0; i &lt; 20; i++) {\n        list.push({\n          title: '\u5206\u7c7b:' + categoryId + ',\u6807\u9898:' + i,\n          img_url: 'https:\/\/picsum.photos\/200\/300?random=' + i\n        });\n      }\n      resolve({\n        list, \/\/ \u5f53\u524d\u9875\u7684\u6570\u636e\n        page, \/\/ \u5f53\u524d\u9875\u7801\n        totalPages: 100 \/\/ \u540e\u7aef\u8fd4\u56de\u7684\u603b\u9875\u6570\n      });\n    }, 1000);\n  });\n}\n\nfunction loadPageData(categoryId, page) {\n  \/\/ \u5224\u65ad\u662f\u5426\u6b63\u5728\u52a0\u8f7d\u4e2d\n  if (isLoading) {\n    return;\n  }\n  isLoading = true;\n  getData(categoryId, page).then(({ list, page, totalPages }) =&gt; {\n    \/\/ \u66f4\u65b0\u603b\u9875\u6570\n    total = totalPages;\n    let html = \"\";\n    for (var i = 0; i &lt; list.length; i++) {\n      html += '&lt;div&gt;@@##@@&lt;span&gt;\"' + list[i].title + '\"&lt;\/span&gt;&lt;\/div&gt;';\n    }\n    $(\".tab_item\").append(html);\n  }).finally(() =&gt; {\n    isLoading = false;\n  });\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.php.cn\/faq\/'%20+%20list%5Bi%5D.img_url%20+%20'\" class=\"aligncenter\" title=\"\u5982\u4f55\u5b9e\u73b0\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\uff1f\u63d2\u56fe1\" alt=\"\u5982\u4f55\u5b9e\u73b0\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\uff1f\u63d2\u56fe1\" \/> <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5b9e\u73b0\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u89e3\u51b3\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5bf9\u5e94\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\u7684\u95ee\u9898 \u8981\u89e3\u51b3\u70b9\u51fb\u6309\u94ae\u5f39\u7a97\u3001\u52a0\u8f7d\u5206\u7c7b\u6570\u636e\u5e76\u6eda\u52a8\u7ffb\u9875\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a \u5b9a\u4e49\u53d8\u91cf\u8bb0\u5f55\u72b6\u6001 \u5b9a\u4e49\u53d8\u91cf\u6765\u8bb0\u5f55\u5f53\u524d\u5206\u7c7bID\u3001\u5f53\u524d\u9875\u7801\u548c\u603b\u9875\u6570\u3002 \u52a0\u8f7d\u6570\u636e\u51fd\u6570 \u521b\u5efa\u51fd\u6570\uff0c\u7528\u4e8e\u52a0\u8f7d\u6307\u5b9a\u5206\u7c7bID\u3001\u9875\u7801\u7684\u6570\u636e\u3002 \u6eda\u52a8\u4e8b\u4ef6\u76d1\u542c \u5728\u5185\u5bb9\u533a\u57df\u6dfb\u52a0\u6eda\u52a8\u4e8b\u4ef6\u76d1\u542c\uff0c\u5f53\u6eda\u52a8\u5230\u5e95\u90e8\u65f6\uff0c\u89e6\u53d1\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u3002 API \u8bf7\u6c42 \u4f7f\u7528 API \u8bf7\u6c42\u52a0\u8f7d\u6570\u636e\uff0c\u5e76\u5c06\u8fd4\u56de\u7684\u6570\u636e\u8ffd\u52a0\u5230\u5185\u5bb9\u533a\u57df\u3002 \u76d1\u542c \u76d1\u542c\u6309\u94ae\u548c\u9009\u9879\u5361\u7684\u70b9\u51fb\u4e8b\u4ef6\uff0c\u66f4\u65b0\u5206\u7c7bID\u548c\u9875\u7801\uff0c\u5e76\u52a0\u8f7d\u6570\u636e\u3002 \u793a\u4f8b\u4ee3\u7801 \/\/ \u4e0d\u9700\u8981\u603b\u9875\u6570\uff0c\u56e0\u4e3a\u603b\u9875\u6570\u662f\u540e\u7aef\u8fd4\u56de\u7684\uff0c\u524d\u7aef\u4e0d\u9700\u8981\u77e5\u9053\u603b\u9875\u6570\uff0c\u53ea\u9700\u8981\u77e5\u9053\u5f53\u524d\u9875\u7801\u5373\u53ef let categoryId = 1, currentPage = 1, total = 0; let isLoading = false; $(document).on(&#8216;click&#8217;, &#8216;.btn&#8217;, function () { loadCategoryData(categoryId, currentPage); }) $(&#8216;.tab_p p&#8217;).click(function () { currentPage = 1; categoryId = $(this).data(&#8216;id&#8217;); \/\/ \u52a0\u8f7d\u5bf9\u5e94\u5206\u7c7b\u7684\u6570\u636e loadCategoryData(categoryId, currentPage); }) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3628","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3628"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3628\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}