Meteor ToDo App实例
C:\Users\Administrator\Desktop>meteor create todo-app
创建成功后生成目录结构如下所示(看网络情况,可能需要好几分钟才能完成):

要查看应用程序,需要运行的命令 meteor 应用程序,然后在浏览器中打开URL:http://localhost:3000
C:\Users\Administrator\Desktop\todo-app>meteor
取而代之默认的文件结构,我们将重构它。让我们创建 client 文件夹,并创建 todo-app.html, todo-app.css和todo-app.js。
创建项目时程序自动创建了 client 和 server 这两个目录,这里我们先要把 client 和 server 这两个目录中的文件内容清空,接着再创建以下所需的文件,执行如下命令:
C:\Users\Administrator\Desktop\todo-app\client>touch todo-app.html
C:\Users\Administrator\Desktop\todo-app\client>touch todo-app.js
C:\Users\Administrator\Desktop\todo-app\server>touch server.js
C:\Users\Administrator\Desktop\todo-app>mkdir server
C:\Users\Administrator\Desktop\todo-app\collections>touch task-collection.js


步骤 3 - client/todo-app.html
我们开发的第一个开发步骤是为应用程序创建HTML。我们需要输入字段,来添加新的任务。任务将有删除和检查功能列表的形式。我们也将显示或隐藏已完成的任务的功能。
<head>
<title>Todo App</title>
</head> <body>
<h1>Todo List ({{incompleteCount}})</h1> <label class = "hide-completed">
<input type = "checkbox" checked = "{{hideCompleted}}" />
Hide Completed Tasks
</label> <form class = "new-task">
<input type = "text" name = "text" placeholder = "Add new tasks" />
</form> <ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul> </body> <template name = "task">
<li class = "{{#if checked}}checked{{/if}}">
<button class = "delete">x</button>
<input type = "checkbox" checked = "{{checked}}" class = "toggle-checked" />
<span>{{username}} - {{text}}</span>
</li>
</template>
步骤4 - collections/task-collection.js
Tasks = new Mongo.Collection("tasks");
步骤5 - server/server.js
我们将在服务器端定义应用程序的方法。这些方法将来自客户端的调用。在这个文件中,我们还将发布数据库查询功能。
//Publishing tasks from the server...
Meteor.publish("tasks", function () {
return Tasks.find({});
}); //Methods for handling MongoDb Tasks collection data...
Meteor.methods({
addTask: function (text) {
Tasks.insert({
text: text,
createdAt: new Date(),
});
}, deleteTask: function (taskId) {
var task = Tasks.findOne(taskId);
Tasks.remove(taskId);
}, setChecked: function (taskId, setChecked) {
var task = Tasks.findOne(taskId);
Tasks.update(taskId, { $set: { checked: setChecked} });
}
});
步骤 6 - client/todo-app.js
这是主要的客户端JavaScript文件。该文件也可以被重构,但我们会在这里编写所有的客户端代码。首先,我们订阅在服务器上发布的任务集合。然后,我们在创建助手能够处理应用程序逻辑,最后我们定义调用来自服务器的方法事件。
// Subscribing to the published tasks
Meteor.subscribe("tasks"); // Show/Hide functionality
Template.body.helpers({
tasks: function () {
if (Session.get("hideCompleted")) {
// If hide completed is checked, filter tasks
return Tasks.find({checked: {$ne: true}}, {sort: {createdAt: -1}});
} else {
// Otherwise, return all of the tasks
return Tasks.find({}, {sort: {createdAt: -1}});
}
}, hideCompleted: function () {
return Session.get("hideCompleted");
}, incompleteCount: function () {
return Tasks.find({checked: {$ne: true}}).count();
} }); // Events for creating new tasks and Show/Hide functionality. Calling methods from the server Template.body.events({
"submit .new-task": function (event) {
event.preventDefault();
var text = event.target.text.value; Meteor.call("addTask", text);
event.target.text.value = "";
}, "change .hide-completed input": function (event) {
Session.set("hideCompleted", event.target.checked);
} }); // Events for Deleting and Check/Uncheck functionality
Template.task.events({
"click .toggle-checked": function () {
// Set the checked property to the opposite of its current value
Meteor.call("setChecked", this._id, ! this.checked);
}, "click .delete": function () {
Meteor.call("deleteTask", this._id);
} });
我们正在开发完成后,我们可以在命令提示符窗口中部署应用程序。应用程序的部署名称是 my-first-todo-app。
C:\Users\Administrator\Desktop\todo-app>meteor deploy my-first-todo-app



C:\Users\Administrator\Desktop\todo-app>meteor add session
Meteor ToDo App实例的更多相关文章
- Lumen开发:lumen源码解读之初始化(1)——app实例
版权声明:本文为博主原创文章,未经博主允许不得转载. 有些注释来着原文的百度翻译,可以有些难理解或者奇怪,我后面会根据自己的理解做调整的哈!!!不喜勿喷,层主英语不过关... 先来看看入口文件publ ...
- 写一个TODO App学习Flutter本地存储工具Moor
写一个TODO App学习Flutter本地存储工具Moor Flutter的数据库存储, 官方文档: https://flutter.dev/docs/cookbook/persistence/sq ...
- [转]使用Xcode 4发布App 实例操作
使用xcode 4发布app 实例操作是本文介绍的内容,不多说,我们直接进入话题. 1.iOS Provisioning Portal 和iTunes Connect 没有变,下载与安装.mobile ...
- Swift 书面 ToDo App
下面的代码是使用的全部Xcode Version 6.0.1 (6A317)书面. 因为当使用团队开发stroyboard在并购的诸多不便的时间,所有或使用.xib该文件准备ToDo App. 想要实 ...
- Flask之app实例的参数配置
说是app实例的配置, 实际也就是flask程序的配置 Flask 是一个非常灵活且短小精干的web框架 , 那么灵活性从什么地方体现呢? 有一个神奇的东西叫 Flask配置 , 这个东西怎么用呢? ...
- 小程序中关于获取app实例与当前组件
1.getApp()来获取 App 实例 2.getCurrentPages()获取前页面栈
- Android经典项目开发之天气APP实例分享
原文:Android经典项目开发之天气APP实例分享 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/mzc186/article/details/5 ...
- react native 实现TODO APP
前端有一个todo app非常适合入门练手 react-native 实现todo app:https://github.com/nwgdegitHub/TODO_RN.git
- .NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App
作者:Steven Giesel 翻译:Alan Wang 校对:李卫涵 – 微软 MVP 排版:Rani Sun 有什么比参考包含分步说明和代码示例的动手教程更好的学习新技术的方式呢?当你完成或 f ...
随机推荐
- js实现ctrl+v粘贴并上传图片
前端页面: <textarea class="scroll" id="text" placeholder="在此输入...">& ...
- svn批处理语句
sc create SVNService binpath="O:\ProgramingSoftware\SuiVersion\bin\svnserve.exe --service -r E: ...
- vue $parent 的上一级 有可能不是父组件,需要好几层$parent 如果这样 还不如用 this.$emit
vue $parent 的上一级 有可能不是父组件,需要好几层$parent 如果这样 还不如用 this.$emit
- Redis进阶例子
工作中用到的RabbitMQ例子 , 但是最后没有用 , 用的CMQ , 顺便说下CMQ社区真的少 , 并且功能少 . 一.消息体 package com.bootdo.common.rabbitmq ...
- 左右分栏页面右侧无法出现滚动条bug
问题记录 项目比较老了,左右分栏的页面,导航栏右边是一个iframe组成的页面,通过某个操作后,页面右侧内容区域无法实现滚动 问题查明 遇见过好几次,最后查明,总结一句话,修改了右侧页面body的ov ...
- 乘法逆元-洛谷-P3811
题目背景 这是一道模板题 题目描述 给定n,p求1~n中所有整数在模p意义下的乘法逆元. 输入输出格式 输入格式: 一行n,p 输出格式: n行,第i行表示i在模p意义下的逆元. 输入输出样例 输入样 ...
- [LUOGU] P3611 [USACO17JAN]Cow Dance Show奶牛舞蹈
https://www.luogu.org/problemnew/show/P3611 二分答案+优先队列 二分O(logn) 判一次正确性O(nlogn) 总体O(nlognlogn) 为了让pri ...
- JAVA:windows myeclipse jdk tomcat maven 完美搭建
文章来源:http://www.cnblogs.com/hello-tl/p/8305027.html 0.下载所需安装包 jdk-7u71-windows-x64.exe 链接:http://p ...
- Mysql ICP(翻译)
英文版原文链接 https://mariadb.com/kb/en/library/index-condition-pushdown/ ICP 全称 Index Condition Pushdown. ...
- 又见GCD (已知最大公约数和其中一个数求另一个数)
#include<cstdio> int f1(int a,int b) //最大公约数 { ) return b; else return f1(b,a%b); } int f2(int ...