添加refresh方法
This commit is contained in:
parent
b6623e0b35
commit
267957214c
|
@ -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;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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>
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue