From 785449b23c5c89e68cddaeb4f4823890a5f61f53 Mon Sep 17 00:00:00 2001 From: HEnG Date: Sun, 1 Feb 2015 17:23:13 +0800 Subject: [PATCH] update remove and left times. --- index.html | 9 +++++++-- scripts/app.js | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index c7f9892..9553e55 100644 --- a/index.html +++ b/index.html @@ -21,7 +21,7 @@

Avalon todo

{{el.content}} - 删除 + 删除
@@ -32,7 +32,12 @@

Avalon todo

- 总共 {{things.size()}} 件, 还剩 {{lefts}} 件未做. + + 还没添加待做事件~ + + + 总共 {{things.size()}} 件, 还剩 {{lefts}} 件未做. + 清除所有
diff --git a/scripts/app.js b/scripts/app.js index 62d53a9..ca8dcc5 100644 --- a/scripts/app.js +++ b/scripts/app.js @@ -6,8 +6,8 @@ var app = avalon.define("todoCtrl", function(vm) { done: true, content: "这几天学学AVALON。" }]; - vm.editIndex = -1; - console.log(vm.things); + vm.editIndex = null; + // 计算未完成数量 vm.getLefts = function() { return vm.things.filter(function(post) { @@ -15,7 +15,7 @@ var app = avalon.define("todoCtrl", function(vm) { }).length; }; - // 更新未完成数量 + // 更新 vm.update = function() { vm.lefts = vm.getLefts(); }; @@ -26,8 +26,12 @@ var app = avalon.define("todoCtrl", function(vm) { if (e.which === 13 && this.value) { var item = { done: false, - content: this.value + content: this.value.trim() }; + if(item.content === "") { + alert("不能为空"); + return false; + } vm.things.push(item); this.value = ""; vm.update(); @@ -43,6 +47,10 @@ var app = avalon.define("todoCtrl", function(vm) { that.querySelector(".inp").select(); }); } + vm.del = function($remove) { + $remove(); + vm.update(); + } vm.editBlur = function() { console.log("input blur"); vm.editIndex = -1;