问题
Context:
I keep carrying out tests about web component composition in different contexts. Please refer to Accessing the parent context of a web component being either DOM or Shadow DOM for details. In this case, I am including in my tests insertion points within the searching space.
Problem:
Let's suppose we have several instances of <x-target>
element that we are trying to find. Points from whence those <x-target>
are intended to be located will be <x-searcher>
elements. The searching process is aimed to follow the closest nested scope rule typical in compiler theory. That is, each <x-searcher>
tag looks for a <x-target>
in each scope and if it is found it will be returned but otherwise it climbs up to the parent scope and the search will be repeated up to the root be it in a template or in a document.
Let's consider the following snippet of pseudo-code. In my previous post, referred in the context, Scott Miles gave a suggestion that inspired me the solution for my problem in a similar context. That problem was essentially the same as this one but instead of using an insertion point to <x-searcher>
in place (A) it included literally that tag. In that context, the behavior of <x-searcher>
was as expected. The tag retrieved the <x-target>
tag with id='2'
. Nevertheless, in this context, using insertion points, the element got by <x-searcher>
inserted in (A) returns the <x-target>
tag with id='1'
. It seems that the searching process with insertion points is carried out on the place where <x-searcher>
lives and not within the template where it is inserted.
<x-target id=”1”>
<x-wrapper>
<x-searcher>
</x-wrapper>
<polymer-element name=”x-wrapper”>
<template>
<x-target id=”2”>
<content select=”x-searcher”></content> <!-- (A) -->
</template>
</polymer-element>
<polymer-element name=”x-searcher”>
<template>
...
</template>
<script>
Polymer ('wc-searcher', {
...
search: function () {
a while-based search suggested by Scott Miles in the referred post
}
});
</script>
</polymer-element
Question:
Could anyone provide a solution or some hints about how can I proceed to solve my problem? Thanks in advance, Javier.
来源:https://stackoverflow.com/questions/24060397/searching-tags-across-nested-scopes-involving-insertion-points