Skip to content

Commit

Permalink
update remove and left times.
Browse files Browse the repository at this point in the history
  • Loading branch information
favrio committed Feb 1, 2015
1 parent e77df51 commit 785449b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 7 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1>Avalon todo</h1>
<div class="normal">
<input type="checkbox" ms-duplex-checked="el.done" data-duplex-changed="update" />
<span>{{el.content}}</span>
<a href="javascript:;" class="item-del" ms-click="$remove">删除</a>
<a href="javascript:;" class="item-del" ms-click="del($remove)">删除</a>
</div>
<div class="edit">
<input type="text" class="inp" ms-duplex="el.content" ms-blur="editBlur" />
Expand All @@ -32,7 +32,12 @@ <h1>Avalon todo</h1>
</div>
<div class="foot">
<span class="lefts">
总共 {{things.size()}} 件, 还剩 {{lefts}} 件未做.
<span ms-if="!things.size()">
还没添加待做事件~
</span>
<span ms-if="things.size()">
总共 {{things.size()}} 件, 还剩 {{lefts}} 件未做.
</span>
</span>
<a href="javascript:;" class="clear-all" ms-click="clear">清除所有</a>
</div>
Expand Down
16 changes: 12 additions & 4 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ 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) {
return post.done !== true;
}).length;
};

// 更新未完成数量
// 更新
vm.update = function() {
vm.lefts = vm.getLefts();
};
Expand All @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit 785449b

Please sign in to comment.