使用JQuery选择Polymer <content>

时间:2016-09-02 22:01:07

标签: javascript jquery html polymer-1.0

是否可以使用JQuery选择Polymer <content>标签内的内容?如果不是JQuery,还有其他方法吗?

<link rel="import" href="elements.html">
<script src="../bower_components/page/page.js"></script>
<script src="../bower_components/jquery/dist/jquery.js"></script>

<dom-module id="jager-pages">
    <template>

        <iron-pages id="pages" attr-for-selected="route">
            <content id="content">
                <!--Render Pages-->
            </content>
        </iron-pages>

    </template>


    <script>
        Polymer({
            ready: function () {
                var pages = $(this.$.pages);

                //Setup Routing
                $('[route]', pages).each(function (index, element) {
                    //Each of these elements should have been passed in as content and have a 'route' tag.
                    var route = $(element).getAttribute('route');
                    prompt(index + ': ' + route);

                    page(route, function () {
                        console.log('Routing to -> ' + route + '!');
                        $(pages).select(route);
                    });
                });

                page({
                    hashbang: true
                });
            }
        });
    </script>
</dom-module>

这是我的自定义元素,我需要进行JQuery(或其他)调用以循环遍历&#34; route&#34;的值。属性存在。

<jager-pages>
    <!--Pages-->
    <section route="/home">
        <h1>Home!</h1>
    </section>
    <section route="/info">
        <h1>Info!</h1>
    </section>
    <section route="/about">
        <h1>About!</h1>
    </section>

</jager-pages>

这是元素内容的一个例子。

我能够用$(此。$。内容)选择和包装内容,但$(此。$。内容).find(&#39; [路由]&#39;)不会什么都归还。好像内容从未被添加或其他东西。

0 个答案:

没有答案