let desiredApp; for (let i = 0; i < apps.length; i++) { if (apps[i].name === hildren[i].tagName) { desiredApp = apps[i]; break; } }将desiredApp改为app_message
时间: 2024-01-08 11:02:28 浏览: 50
可以这样修改代码:
let app_message;
for (let i = 0; i < apps.length; i++) {
if (apps[i].name === children[i].tagName) {
app_message = apps[i];
break;
}
}
这样就把 desiredApp 改为了 app_message。
相关问题
把所有的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); } }
) { 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。
不使用回调js从apps数组中找到有name属性为hildren[i].tagName的对象
您可以使用循环和条件语句来遍历apps数组,并在每个对象中查找是否存在name属性为hildren[i].tagName。以下是一种可能的解决方案:
```
let desiredApp;
for (let i = 0; i < apps.length; i++) {
if (apps[i].name === hildren[i].tagName) {
desiredApp = apps[i];
break;
}
}
// desiredApp 现在是具有指定名称属性的对象
```
阅读全文