简体   繁体   English

如何在Polymer中继承变量?

[英]How to inherit a variable in Polymer?

I have the following HTML. 我有以下HTML。

<iron-pages id="pages" role="main" selected="[[_page]]" attr-for-selected="name">

    <marked-element name="[[_page]]">
        <div slot="markdown-html"></div>
        <script type="text/markdown" src="/src/markdown/[[_page]].md"></script>
    </marked-element>

</iron-pages>

The [[_page]] variable works fine except as src value. [[_page]]变量可以作为src值正常工作。 The result is: marked-element.html:315 GET http://localhost:8081/src/markdown/.md 404 (Not Found) 结果是: marked-element.html:315 GET http://localhost:8081/src/markdown/.md 404 (Not Found)

How can I make marked-element inherit the _page variable? 如何使marked-element继承_page变量?

Polymer does not allow to create/append strings inline so you have to create a new variable with the complete string in it. Polymer不允许内联创建/附加字符串,因此您必须创建一个包含完整字符串的新变量。 Also if you want to write something in a default html attribute like src you have to add a $ to its name. 另外,如果您想在默认的html属性(例如src)中编写内容,则必须在其名称中添加$。

<script type="text/markdown" src$="[[_url]]"></script>

//Somewhere in your component
this.set('_url', '/src/markdown/' + this._page + '.md');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM