{"id":5706,"date":"2017-03-16T14:04:35","date_gmt":"2017-03-16T06:04:35","guid":{"rendered":"https:\/\/sdeno.com\/?p=5706"},"modified":"2017-04-05T16:48:50","modified_gmt":"2017-04-05T08:48:50","slug":"meteor-js%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=5706","title":{"rendered":"meteor.js\u7b14\u8bb0"},"content":{"rendered":"<p><a href=\"https:\/\/sdeno.com\/wp-content\/uploads\/2017\/03\/meteor.txt\">meteor.txt<\/a><\/p>\n<p><span style=\"color: #ff0000;\">1\uff0clinux mac\u5b89\u88c5\u65b9\u6cd5<\/span><br \/>\ncurl https:\/\/install.meteor.com\/ | sh<br \/>\n\u6839\u636e\u63d0\u793a\u521b\u5efa\u9879\u76ee\u76ee\u5f55\u548c\u5b89\u88c5\u6a21\u5757<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">2\uff0c\u76ee\u5f55\u4ecb\u7ecd<\/span><br \/>\nclient\/main.html \/\/\u76f8\u5f53\u4e8eindex.html\uff0c\u6240\u6709\u7684\u6a21\u5757\u90fd\u63d2\u5165\u5230\u9875\u9762\u4e2d<br \/>\nclient\/main.js \/\/main.html\u7684\u4e00\u4e9b\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u90fd\u5728\u8fd9\u91cc\u5199<br \/>\nclient\/main.css \/\/\u6dfb\u52a0\u6837\u5f0f<br \/>\nserver\/main.js \/\/\u5411\u670d\u52a1\u5668\u63d0\u4ea4\u6570\u636e<\/p>\n<p>\/\/\u5e0c\u671b\u52a0\u8f7d\u989d\u5916\u989d\u63d2\u4ef6<br \/>\n\u5728client\u76ee\u5f55\u4e0b\u624b\u52a8\u521b\u5efalib\u76ee\u5f55<br \/>\n\u4f8b\u5982\uff1aclient\/lib\/jquery.js \/\/\u8fd0\u884cmeteor\u5c31\u4f1a\u81ea\u52a8\u52a0\u8f7djquery<br \/>\n\u4f8b\u5982\uff1aclient\/lib\/css.css \/\/\u8fd0\u884cmeteor\u5c31\u4f1a\u81ea\u52a8\u52a0\u8f7dcss.css<br \/>\n\/\/\u5c06\u6570\u636e\u5e93\u4fe1\u606f\u63d2\u5165\u5230\u6a21\u677f\u4e2d\u3002\uff08meteor\u53ea\u652f\u6301mongodb\uff09<br \/>\n\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e2d\u624b\u52a8\u521b\u5efalib\/collection\u76ee\u5f55<br \/>\n\u4f8b\u5982\uff1alib\/collection\/users.js<\/p>\n<p>\u5185\u5bb9\uff1a<br \/>\n\/\/\u4e0d\u80fd\u52a0var\u4e0d\u7136\u5c31\u6210\u4e86\u5c40\u90e8\u53d8\u91cf\u4e86\uff0c\u8981\u5b9e\u73b0\u5168\u5c40\u53d8\u91cf\u8fd9\u6837\u4efb\u610f\u7684\u6a21\u5757\u90fd\u80fd\u8c03\u7528<br \/>\nUsers=new Mongo.Collection(&#8216;users&#8217;);<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">3\uff0cBlaze\u6a21\u677f<\/span><br \/>\n\u53ef\u4ee5\u5b9e\u73b0\u540e\u53f0\u6570\u636e\u6709\u53d8\u5316\u524d\u53f0\u9875\u9762\u4f1a\u5b9e\u73b0\u81ea\u52a8\u5237\u65b0\u8fd9\u5c31\u662f\u54cd\u5e94\u5f0f<br \/>\n\u53ea\u8981html\u3001js\u3001css\u6709\u53d8\u5316\u9875\u9762\u5c31\u4f1a\u81ea\u52a8\u5237\u65b0<\/p>\n<p>\uff081\uff09\u5728client\u76ee\u5f55\u4e0b\u521b\u5efauser.html<\/p>\n<pre> \u5185\u5bb9\uff1a\r\n&lt;template name=\"user_list\"&gt; &lt;!--\u6a21\u677f\u547d\u540d\uff0c\u540d\u5b57\u5fc5\u987b\u662f\u552f\u4e00\u7684user_list--&gt;\r\n &lt;p&gt;{{xx}}&lt;\/p&gt; &lt;!--xx\u662f\u8981\u4ece\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u4e2d\u8c03\u7528\u51fa\u6765\u7684\u6570\u636e--&gt;\r\n &lt;ul&gt;\r\n {{#each users }}\r\n   &lt;li&gt;\r\n     name:{{name}}----age:{{age}}\r\n   &lt;\/li&gt;\r\n {{\/each}}\r\n &lt;\/ul&gt;\r\n&lt;\/template&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>\uff082\uff09\u5728client\u76ee\u5f55\u4e0b\u521b\u5efauser.js<\/p>\n<pre>import { Template } from 'meteor\/templating';\r\nTemplate.user_list.helpers({\r\n xx:\"xxx1\",\r\n users:function () {\r\n   return Users.find() \/\/Users.find()\u662f\u4ecemongodb\u6570\u636e\u4e2d\u83b7\u53d6\u6570\u636e\r\n }\r\n});<\/pre>\n<p>&nbsp;<\/p>\n<p>\uff083\uff09\u521b\u5efa\u76ee\u5f55\u548cjs\uff0clib\/collection\/users.js<\/p>\n<pre>Users=new Mongo.Collection('users');<\/pre>\n<p>&nbsp;<\/p>\n<p>\uff084\uff09\u7f16\u8f91client\/main.html<\/p>\n<p>\u5728main.html\u9875\u9762\u9700\u8981\u63d2\u5165\u6253\u5730\u65b9\uff0c\u52a0\u5165<\/p>\n<pre>{{&gt; user_list}}<\/pre>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-\u4ee5\u4e0a\u5927\u6982\u4ecb\u7ecd\u4e86meteor\u4e0e\u6570\u636e\u5e93\u7684\u4ea4\u4e92\u6d41\u7a0b&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>\u4e0b\u9762\u4ecb\u7ecdBlaze\u6a21\u677f\u57fa\u7840\u7528\u6cd5\uff1a<\/p>\n<p>{{name}} \/\/\u4e0d\u89e3\u6790html\u4ee3\u7801\uff0c\u5199\u4ec0\u4e48\u4ee3\u7801\u76f4\u63a5\u663e\u793a\u51fa\u6765<br \/>\n{{{name}}} \/\/\u89e3\u6790html\u4ee3\u7801<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/\u5b9a\u4e49\u4e00\u4e2a\u6a21\u677f<\/p>\n<pre>&lt;template name=\"xx1\"&gt; \/\/xx\u547d\u540d\u5fc5\u987b\u8981\u552f\u4e00\r\n ...\r\n&lt;\/template&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/\u5f15\u7528\u4e00\u4e2a\u6a21\u677f<\/p>\n<pre>{{&gt; xx1}}<\/pre>\n<p>&nbsp;<\/p>\n<p>\/\/\u76f8\u4e92\u5d4c\u5957<\/p>\n<pre>&lt;template name=\"xx1\"&gt; \/\/xx\u547d\u540d\u5fc5\u987b\u8981\u552f\u4e00\r\n {{&gt; xx2}}\r\n&lt;\/template&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>\/\/\u6761\u4ef6<\/p>\n<pre> {{#if true}}\r\n    &lt;p&gt;\u771f&lt;\/p&gt;\r\n {{else}}\r\n    &lt;p&gt;\u5047&lt;\/p&gt;\r\n {{\/if}}<\/pre>\n<p>&nbsp;<\/p>\n<pre>&lt;template name=\"ifelse\"&gt;\r\n  {{#if panduan canshu}}\r\n    {{&gt; test}}\r\n  {{else}}\r\n &lt;p&gt;\u6ca1\u6709&lt;\/p&gt;\r\n {{\/if}}\r\n&lt;\/template&gt;\r\n\r\n Template.ifelse.helpers({\r\n   canshu:'11111',\r\n   panduan:function (canshu) {\r\n      return !!canshu &amp;&amp; canshu.length&gt;5;\r\n   }\r\n });<\/pre>\n<p>&nbsp;<\/p>\n<pre>{{#unless false}} \/\/\u4e0eif\u76f8\u53cd\r\n &lt;p&gt;\u771f&lt;\/p&gt;\r\n {{else}}\r\n &lt;p&gt;\u5047&lt;\/p&gt;\r\n{{\/unless}}<\/pre>\n<p>&nbsp;<\/p>\n<p>\/\/\u904d\u5386<\/p>\n<pre> {{#each arry}}\r\n   &lt;p&gt;{{name}}---{{age}}&lt;\/p&gt;\r\n {{\/each}}\r\n\r\n\r\narry:function () {\r\n return [{name:'11'},{age:22},{name:'11'},{age:22}]\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>{{#each arry}}\r\n &lt;p&gt;{{this}}&lt;\/p&gt;\r\n {{\/each}}\r\n\r\narry:function () {\r\n return ['123','456']\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>\/\/\u4e0a\u4e0b\u6587<br \/>\n{{#with}}<br \/>\n\u6a21\u677f\u52a8\u6001\u6570\u636e\u4e1a\u52a1\u903b\u8f91helpers\uff0c\u6709\u5173\u4e00\u4e9b\u52a8\u6001\u6570\u636e\u7684\u5224\u65ad\u90fd\u5199\u5728helpers\u5bf9\u8c61\u4e2d<br \/>\n\u4f7f\u7528\u4e4b\u524d\u5148\u5f15\u5165import { Template } from &#8216;meteor\/templating&#8217;;<\/p>\n<p>\u5c40\u90e8\uff1a\u4ec5\u4ec5\u5728xxx\u6a21\u677f\u4e2d\u8d77\u4f5c\u7528<\/p>\n<pre>Template.xxx.helpers({\r\n ...\r\n});<\/pre>\n<p>&nbsp;<\/p>\n<p>\u5168\u5c40\uff1a\u4efb\u610f\u6a21\u677f\u4e2d\u90fd\u53ef\u4ee5\u8c03\u7528\u8be5\u53d8\u91cf<\/p>\n<pre>Template.registerHelper('\u53d8\u91cf\u540d',(a,b)=&gt;{\r\n  return a===b;\r\n});\r\n\r\n\u67d0\u6a21\u677f\u5185\uff1a\r\n&lt;input type=\"checkbox\" checked={{\u53d8\u91cf\u540d select 'yes'}}&gt;\r\nTemplate.xxx.helpers({\r\n  select:'yes'\r\n});<\/pre>\n<p>&nbsp;<\/p>\n<p>\u4e8b\u4ef6\u7ed1\u5b9a<br \/>\n\u6a21\u677f\u5185\u7f6e\u4e86jQuery\uff0c\u4e5f\u5c31\u662f\u8bf4\u5e73\u65f6\u6211\u4eec\u5728\u524d\u53f0\u64cd\u4f5c\u7684dom\uff0c\u8f6c\u5728\u4e86\u540e\u53f0\u5199\u3002<br \/>\nclick<br \/>\ndbclick<br \/>\nfocus<br \/>\nblur<br \/>\nchange<br \/>\nmouseenter\/mouseleave<br \/>\nmousedown\/mouseup<br \/>\nkeydown\/keypress\/keyup<\/p>\n<p>\u6848\u4f8b\uff1a<\/p>\n<pre>Template.xx.events({\r\n  \"click button\":function(event,template){\r\n      ...\r\n  },\r\n  \"mouseenter #myid\":function(event,template){\r\n      ...\r\n  }\r\n});<\/pre>\n<p>\/\/\u963b\u6b62\u5192\u6ce1<br \/>\nevent.stopImmediatePropagation();<\/p>\n<p>\/\/\u963b\u6b62\u9ed8\u8ba4\u884c\u4e3a<br \/>\nevent.preventDefault();<\/p>\n<p>&nbsp;<\/p>\n<p>\u6a21\u677f\u7684\u751f\u547d\u5468\u671f\uff1a(\u8bf4\u767d\u4e86\u5c31\u662f\u6a21\u677f\u5728\u4e0d\u540c\u65f6\u671f\u7684\u56de\u8c03\u51fd\u6570)<\/p>\n<pre>Template.xxx.onCreated(function(){\r\n  \/\/\u6a21\u677f\u7684\u5b9e\u4f8b\u5316\u5b8c\u6210\uff0c\u4f46\u662f\u8fd8\u770b\u89c1\uff0c\u9002\u5408\u8bbe\u7f6e\u521d\u59cb\u5316\u7684\u53d8\u91cf\r\n  this.haha='123'; \/\/\u8bbe\u7f6e\u521d\u59cb\u5316\u53d8\u91cf \uff0c\u60f3\u5728helpers\u548cevents\u51fd\u6570\u4e2d\u83b7\u53d6\u5230\u6b64\u53d8\u91cf\u4f7f\u7528Template.instance().haha;\r\n});<\/pre>\n<p>&nbsp;<\/p>\n<pre>Template.xxx.onRendered(function () {\r\n  \/\/dom\u5df2\u7ecf\u5728\u9875\u9762\u5b58\u5728\uff0c\u7528\u6237\u53ef\u4ee5\u770b\u89c1\u4e86\uff0c\u9700\u8981\u7528js\u64cd\u4f5cdom\u5c31\u5728\u6b64\u6b65\u8fdb\u884c\u64cd\u4f5c\r\n});<\/pre>\n<p>&nbsp;<\/p>\n<pre>Template.xxx.onDestroyed(function () {\r\n  \/\/\u6a21\u677f\u88ab\u9500\u6bc1\u65f6\u5019\u56de\u8c03\r\n});<\/pre>\n<p>&nbsp;<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\u4e0emongodb\u6570\u636e\u5e93\u4ea4\u4e92<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>\u7528mysql\u7684\u6982\u5ff5\u6765\u7406\u89e3mongodb<\/p>\n<p>\u5e93&#8212;\u96c6\u5408<br \/>\n\u8868&#8212;\u6587\u6863<br \/>\n\u5b57\u6bb5&#8212;\u952e\u503c\u5bf9<\/p>\n<p>1\uff0c\u8fdb\u5165mongodb<br \/>\nmeteor mongo<\/p>\n<p>\u589e\u5220\u6539\u67e5\uff1ahttps:\/\/sdeno.com\/?p=5397<br \/>\n2\uff0cmeteor\u8fde\u63a5mongodb<\/p>\n<p>lib\/collection\/Users.js<br \/>\nUsers=new Mongo.Collection(&#8216;users&#8217;); \/\/\u8fde\u63a5\u5e76\u83b7\u53d6\u5230users\u96c6\u5408\uff0c\u4e0d\u9700\u8981\u8d26\u53f7\u5bc6\u7801\uff08\u4f46\u662f\u8fd9\u6837\u4e0d\u5b89\u5168\uff09<br \/>\nclient\/user.js<br \/>\nUsers.find(); \/\/\u67e5\u8be2users\u96c6\u5408\u7684\u6240\u6709\u6587\u6863<\/p>\n<p>&nbsp;<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nsession<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\u5728shell\u4e2d\u5207\u6362\u5230meteor\u76ee\u5f55<br \/>\n\u4e0b\u8f7d\u6a21\u5757\uff1ameteor add session<\/p>\n<p>\u5f15\u5165\uff1aimport { Session } from &#8216;meteor\/session&#8217;;<\/p>\n<p>\u83b7\u53d6\uff1aSession.get(&#8216;name&#8217;);<br \/>\n\u8bbe\u7f6e\uff1aSession.set(&#8216;name&#8217;,value);<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\u8def\u7531\uff08\u63a8\u8350\u4f7f\u7528\uff09<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\u5982\u679c\u4f7f\u7528\u8fc7express\u3001koa\u7c7b\u4f3c\u7684\u6846\u67b6\u5b83\u4eec\u90fd\u5185\u7f6e\u4e86\u8def\u7531\u529f\u80fd\uff0c\u800cmeteor\u5185\u7f6e\u6ca1\u6709\u8def\u7531\u529f\u80fd\uff0c\u9700\u8981\u989d\u5916\u5b89\u88c5<br \/>\n\u5b89\u88c5\uff1ameteor add iron:router<br \/>\n\u5b98\u7f51\uff1ahttp:\/\/iron-meteor.github.io\/iron-router\/<\/p>\n<p>&nbsp;<\/p>\n<p>\u5bfc\u822a\uff1a<br \/>\nclient\/nav.html<br \/>\n&lt;template name=&#8221;nav&#8221;&gt;<br \/>\n&lt;ul&gt;<br \/>\n&lt;a href=&#8221;\/&#8221;&gt;\u9996\u9875&lt;\/a&gt;<br \/>\n&lt;a href=&#8221;\/aboutus&#8221;&gt;\u5173\u4e8e&lt;\/a&gt;<br \/>\n&lt;\/ul&gt;<br \/>\n&lt;\/template&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>\u9996\u9875\uff1a<br \/>\nclient\/home.html<\/p>\n<p>&lt;template name=&#8221;home&#8221;&gt;<br \/>\n{{&gt; nav}}<br \/>\n&lt;p&gt;\u8fd9\u91cc\u662f\u9996\u9875&lt;\/p&gt;<br \/>\n&lt;\/template&gt;<br \/>\n\u4e3a\u9996\u9875\u521b\u5efa\u8def\u7531,\u5e76\u6e32\u67d3\u5426\u5219\u9875\u9762\u65e0\u6cd5\u663e\u793a<br \/>\nlib\/router.js<\/p>\n<p>import { Router } from &#8216;meteor\/iron:router&#8217;;<\/p>\n<p>Router.route(&#8216;\/&#8217;,function () {<br \/>\nthis.render(&#8216;home&#8217;); \/\/\u8fd9\u91cc\u7684home\u662f template\u7684\u6a21\u677f\u540d\u79f0home<br \/>\n});<br \/>\n\u6a21\u677f\u548c\u8def\u7531\u90fd\u521b\u5efa\u597d\uff0c\u53ea\u8981\u8bbf\u95eeurl\u5c31\u81ea\u52a8\u5728main.html\u7684body\u6807\u7b7e\u91cc\u9762\u63d2\u5165\u5185\u5bb9\u3002<br \/>\n\u4ee5\u4e0a\u662f\u7b80\u5355\u57fa\u7840\u7684\u7528\u6cd5\uff0c\u4f46\u5982\u679c10\u4e2a\u9875\u9762\u8ddfhome\u6a21\u677f\u4e00\u6837\u90fd\u5f15\u5165\u4e86{{&gt; nav}}\uff0c\u4e4b\u540e\u53c8\u4e0d\u9700\u8981\u7684\u8bdd\uff0c\u5c31\u9700\u8981\u4e00\u4e2a\u4e2a\u5220\u9664\u8fd9\u6837\u4f1a\u6bd4\u8f83\u9ebb\u70e6\u3002<br \/>\n\u8fd9\u4e86\u9700\u8981\u4e86\u89e3{{yield}}\u7684\u7528\u6cd5<\/p>\n<p>\u516c\u5171\u6a21\u677f\uff1a<br \/>\nclient\/public.html<\/p>\n<p>&lt;template name=&#8221;public&#8221;&gt;<br \/>\n{{&gt; nav}}<br \/>\n{{&gt; yield}}<br \/>\n&lt;\/template&gt;<br \/>\n\u9996\u9875<br \/>\nclient\/home.html<\/p>\n<p>&lt;template name=&#8221;home&#8221;&gt;<br \/>\n&lt;!&#8211;\u8ddf\u4e4b\u524d\u76f8\u6bd4\u8fd9\u91cc\u53ef\u4ee5\u4e0d\u9700\u8981{{&gt; nav}}\u4e86&#8211;&gt;<br \/>\n&lt;p&gt;\u8fd9\u91cc\u662f\u9996\u9875&lt;\/p&gt;<br \/>\n&lt;\/template&gt;<br \/>\n\u8def\u7531\uff1a<br \/>\nlib\/router.js<\/p>\n<p>import { Router } from &#8216;meteor\/iron:router&#8217;;<br \/>\nRouter.configure({layoutTemplate:&#8217;public&#8217;}); \/\/\u8fd9\u4ee3\u7801\u8bf4\u660e\uff0c\u9ed8\u8ba4\u6e32\u67d3\u51fa\u6765\u7684\u9875\u9762\u90fd\u9ed8\u8ba4\u5d4c\u5957\u5230public.html\u9875\u9762\u7684{{&gt; yield}}\u4e2d<\/p>\n<p>Router.route(&#8216;\/&#8217;,function () {<br \/>\nthis.render(&#8216;home&#8217;);<br \/>\n});<\/p>\n<p>\/\/\u56e0\u4e3a\u9ed8\u8ba4\u90fd\u4f1a\u52a0\u8f7d\u4e86\u5bfc\u822a\uff0c\u4f46\u662f\u6709\u65f6\u5019\u6211\u4eec\u4e0d\u9700\u8981\u5462\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>Router.route(&#8216;\/aboutus&#8217;,function () {<br \/>\nthis.layout(&#8216;aboutus&#8217;); \/\/\u4f7f\u7528this.layout() \u8bf4\u660e\u5c31\u4e0d\u9700\u8981\u5d4c\u5957\u5230public.html\u6a21\u677f\u4e2d\uff0c\u800c\u662f\u72ec\u7acb\u4f7f\u7528\u81ea\u5df1\u7684aboutus.html\u6a21\u677f<br \/>\n});<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\u8def\u7531\u4e0e\u6570\u636e\u4ea4\u4e92<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>\u5f00\u542fmeteor\u81ea\u5e26\u6570\u636e\u5e93mogodb\uff1a<br \/>\nmeteor mongo<\/p>\n<p>1\uff0c\u5047\u8bbe\u7528Users.find()\u80fd\u67e5\u8be2\u5230\u6570\u636e<\/p>\n<p>2\uff0c\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u6570\u636e<br \/>\nlib\/collection\/User.js<br \/>\nUsers=new Mongo.Collection(&#8216;users&#8217;); \/\/users\u662fmongodb\u6570\u636e\u96c6\u5408<\/p>\n<p>3\uff0c\u5c06\u6570\u636e\u96c6\u5408\u4f20\u5165\u5230\u8def\u7531\u4e2d<br \/>\nRouter.route(&#8216;\/&#8217;,function () {<br \/>\nthis.render(&#8216;home&#8217;,{<br \/>\ndata:function () {<br \/>\nreturn {users:Users.find()} \/\/\u8fd9\u91cc\u7684users\uff0c\u5c31\u662f\u8981\u4f20\u5230\u524d\u53f0\u7684\u53d8\u91cf<br \/>\n}<br \/>\n});<br \/>\n});<br \/>\n4\uff0c\u524d\u53f0\u663e\u793a\u6570\u636e<br \/>\n{{#each users}}<br \/>\n&lt;li&gt;_id:{{_id}}&#8212;-{{name}}&#8212;-{{age}}&lt;\/li&gt;<br \/>\n{{\/each}}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\u8def\u7531\u7684\u751f\u547d\u5468\u671f<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>action: function () {<br \/>\nconsole.log(&#8216;3&#8217;);<br \/>\nthis.render();<br \/>\n},<br \/>\nonRun: function () {console.log(&#8216;1&#8217;);this.next()},<br \/>\nonRerun: function () {console.log(&#8216;\u6267\u884c\u7b2c\u4e8c\u6b21\u65f6\u624d\u88ab\u6267\u884c&#8217;);},<br \/>\nonBeforeAction: function () {console.log(&#8216;2&#8217;);this.next()},<br \/>\nonAfterAction: function () {console.log(&#8216;4&#8217;);},<br \/>\nonStop: function () {console.log(&#8216;\u8def\u7531\u88ab\u9500\u6bc1\u65f6\u6267\u884c&#8217;)}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>meteor.txt 1\uff0clinux mac\u5b89\u88c5\u65b9\u6cd5 curl https:\/\/install.meteor. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[45],"tags":[],"class_list":["post-5706","post","type-post","status-publish","format-standard","hentry","category-meteor"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5706"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5706\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}