{"id":2102,"date":"2024-11-10T10:56:07","date_gmt":"2024-11-10T02:56:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2102\/"},"modified":"2024-11-10T10:56:07","modified_gmt":"2024-11-10T02:56:07","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-fullcalendar-%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%be%aa%e7%8e%af%e5%8a%a8%e6%80%81%e5%86%99%e5%85%a5-events-%e6%95%b0%e6%8d%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2102\/","title":{"rendered":"\u5982\u4f55\u5728 FullCalendar \u4e2d\u4f7f\u7528\u5faa\u73af\u52a8\u6001\u5199\u5165 events \u6570\u636e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173064061354511.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 FullCalendar \u4e2d\u4f7f\u7528\u5faa\u73af\u52a8\u6001\u5199\u5165 events \u6570\u636e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 FullCalendar \u4e2d\u4f7f\u7528\u5faa\u73af\u52a8\u6001\u5199\u5165 events \u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5728 fullcalendar \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u52a8\u6001\u5199\u5165 events \u6570\u636e\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<p><strong>1. \u5b9a\u4e49\u6570\u636e\u6570\u7ec4<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u5b9a\u4e49\u4e00\u4e2a javascript \u6570\u7ec4\u6765\u5b58\u653e events \u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>var events = [\n  {\n    title: '\u5168\u5929\u8ba1\u5212',\n    start: new date(y, m, 1)\n  },\n  {\n    title: '\u5f20\u5bb6\u754c\u56db\u65e5\u6e38',\n    start: new date(y, m, d-5),\n    end: new date(y, m, d-2)\n  },\n  \/\/ ... \u66f4\u591a\u7684\u4e8b\u4ef6\u5bf9\u8c61\n];<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>2. \u5faa\u73af\u5199\u5165 events<\/strong><\/p>\n<p>\u7136\u540e\uff0c\u5728 fullcalendar \u7684 options \u4e2d\u4f7f\u7528\u5faa\u73af\u52a8\u6001\u5199\u5165 events \u6570\u7ec4\u4e2d\u7684\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>events: function() {\n  var eventsarr = [];  \/\/ \u5b9a\u4e49\u4e00\u4e2a\u4e34\u65f6\u7684\u6570\u7ec4\n  for (var i = 0; i &lt; events.length; i++) {\n    eventsarr.push(events[i]);\n  }\n  return eventsarr;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u904d\u5386 events \u6570\u7ec4\uff0c\u5e76\u5c06\u6bcf\u4e2a\u4e8b\u4ef6\u5bf9\u8c61\u6dfb\u52a0\u5230\u4e34\u65f6\u6570\u7ec4 eventsarr \u4e2d\uff0c\u6700\u540e\u5c06 eventsarr \u8fd4\u56de\u7ed9 fullcalendar\u3002<\/p>\n<p><strong>3. \u521d\u59cb\u5316 fullcalendar<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u5728\u521d\u59cb\u5316 fullcalendar \u65f6\uff0c\u5c06\u5305\u542b\u5faa\u73af\u7684 events \u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\uff1a<\/p>\n<pre>$('#calendar').fullCalendar({\n  \/\/ ... \u5176\u4ed6\u9009\u9879\n  events: function() {\n    var eventsArr = [];\n    for (var i = 0; i &lt; events.length; i++) {\n      eventsArr.push(events[i]);\n    }\n    return eventsArr;\n  }\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u6837\uff0cfullcalendar \u7684 events \u6570\u636e\u5c06\u901a\u8fc7\u5faa\u73af\u52a8\u6001\u5199\u5165\uff0c\u53ef\u4ee5\u5b9e\u73b0\u7075\u6d3b\u5730\u6dfb\u52a0\u6216\u4fee\u6539\u4e8b\u4ef6\u6570\u636e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 FullCalendar \u4e2d\u4f7f\u7528\u5faa\u73af\u52a8\u6001\u5199\u5165 events \u6570\u636e\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>\u5728 fullcalendar \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u52a8\u6001\u5199\u5165 events \u6570\u636e\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a 1. \u5b9a\u4e49\u6570\u636e\u6570\u7ec4 \u9996\u5148\uff0c\u5b9a\u4e49\u4e00\u4e2a javascript \u6570\u7ec4\u6765\u5b58\u653e events \u6570\u636e\u3002\u4f8b\u5982\uff1a var events = [ { title: &#8216;\u5168\u5929\u8ba1\u5212&#8217;, start: new date(y, m, 1) }, { title: &#8216;\u5f20\u5bb6\u754c\u56db\u65e5\u6e38&#8217;, start: new date(y, m, d-5), end: new date(y, m, d-2) }, \/\/ &#8230; \u66f4\u591a\u7684\u4e8b\u4ef6\u5bf9\u8c61 ]; \u767b\u5f55\u540e\u590d\u5236 2. \u5faa\u73af\u5199\u5165 events \u7136\u540e\uff0c\u5728 fullcalendar \u7684 options \u4e2d\u4f7f\u7528\u5faa\u73af\u52a8\u6001\u5199\u5165 events \u6570\u7ec4\u4e2d\u7684\u6570\u636e\u3002\u4f8b\u5982\uff1a events: [&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-2102","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2102","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=2102"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2102\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}