添加refresh方法

This commit is contained in:
张磊 2015-06-15 08:15:33 +08:00
parent b6623e0b35
commit 267957214c
4 changed files with 56 additions and 1 deletions

4
dist/nuclear.js vendored
View File

@ -78,6 +78,10 @@ Nuclear._mixObj = function (obj) {
if (this.installed) this.installed();
}
obj.refresh = function () {
this._nuclearLocalRefresh();
}
//加if防止子类赋值undefined丢失父类方法
if (obj.render) {
obj._nuclearTplGenerator = obj.render;

2
dist/nuclear.min.js vendored

File diff suppressed because one or more lines are too long

47
example/todo4.html Normal file
View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>Todo</title>
</head>
<body>
<div id="container"></div>
<script src="../dist/nuclear.js"></script>
<script type="text/javascript">
var TodoList = Nuclear.create({
render: function () {
return '<ul> {{#items}} <li>{{.}}</li> {{/items}}</ul>';
}
});
var TodoApp = Nuclear.create({
install: function () {
this.todoList = new TodoList({ items: [] })
},
onRefresh: function () {
this.form = this.node.querySelector("form");
this.textBox = this.node.querySelector("input");
this.form.addEventListener("submit", function (evt) {
evt.preventDefault();
this.todoList.option.items.push(this.textBox.value);
this.refresh();
}.bind(this), false);
},
render: function () {
return '<div>\
<h3>TODO</h3>'
+ this.todoList.render()+
'<form >\
<input type="text" />\
<button>Add #'+this.todoList.option.items.length+'</button>\
</form>\
</div>';
}
});
new TodoApp( {},"#container");
</script>
<a href="https://github.com/AlloyTeam/Nuclear" target="_blank" style="position: absolute; right: 0; top: 0;">
<img src="http://alloyteam.github.io/AlloyRenderingEngine/asset/img/github.png" alt="" />
</a>
</body>
</html>

View File

@ -59,6 +59,10 @@ Nuclear._mixObj = function (obj) {
if (this.installed) this.installed();
}
obj.refresh = function () {
this._nuclearLocalRefresh();
}
//加if防止子类赋值undefined丢失父类方法
if (obj.render) {
obj._nuclearTplGenerator = obj.render;