Skip to content

Commit 9103f83

Browse files
author
Avaer Kazmer
committed
Add keypath lookup via #selector
1 parent 504cb64 commit 9103f83

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,17 @@
136136
}
137137
function _findElByKeyPath(el, keyPath) {
138138
for (let i = 0; i < keyPath.length; i++) {
139-
el = el.childNodes[keyPath[i]];
140-
if (!el) {
139+
const key = keyPath[i];
140+
let match;
141+
if (typeof key === 'number') {
142+
el = el.childNodes[key] || null;
143+
} else if (typeof key === 'string' && (match = key.match(/^#(.+)$/))) {
144+
const id = match[1];
145+
el = el.childNodes.find(childEl => Array.prototype.some.call(childEl.attributes, attr => attr.name === 'id' && attr.value === id)) || null;
146+
} else {
141147
el = null;
148+
}
149+
if (!el) {
142150
break;
143151
}
144152
}

0 commit comments

Comments
 (0)