把所有的this.app换成app,let apps = []; //root下可执行的app let app = MakeApp(); //遍历vdom结构,用来生成新dom let children = dom.childNodes; for (var i = 0; i < children.length; i++) { if (children[i].nodeType == 1) { if (isHTML(hildren[i].tagName)) { let app = MakeApp(); this.apps.push(app); } else { //从apps数组中找到有name属性为hildren[i].tagName的对象 let app_message; for (let i = 0; i < apps.length; i++) { if (apps[i].name === children[i].tagName) { app_message = apps[i]; break; } } let app = MakeApp(app_message); this.apps.push(app); } } else if (children[i].nodeType === Node.TEXT_NODE && children[i].textContent.trim() !== '') { //判断children[i].nodeType节点是否是一个非空文本节点 let app = MakeApp(); this.apps.push(app); } }
时间: 2024-01-20 12:04:17 浏览: 108
) { let app = MakeApp(); this.apps.push(app); } }
修改为:
let apps = []; //root下可执行的app
let app = MakeApp(); //遍历vdom结构,用来生成新dom
let children = dom.childNodes;
for (var i = 0; i < children.length; i++) {
if (children[i].nodeType == 1) {
if (isHTML(children[i].tagName)) {
let app = MakeApp();
apps.push(app);
} else {
//从apps数组中找到有name属性为children[i].tagName的对象
let app_message;
for (let j = 0; j < apps.length; j++) {
if (apps[j].name === children[i].tagName) {
app_message = apps[j];
break;
}
}
let app = MakeApp(app_message);
apps.push(app);
}
} else if (children[i].nodeType === Node.TEXT_NODE) {
let app = MakeApp();
apps.push(app);
}
}
注意,我已经将代码中的this.apps改为了apps。
阅读全文