簡體   English   中英

dom-if模板不起作用

[英]dom-if template does not work

dom-if模板不起作用。 我有以下聚合物2組分:

<link rel="import" href="../bower_components/polymer/polymer-element.html">

<dom-module id="ohr-block">
    <template>
        <style>
            :host {
                display: block;
            }
        </style>
        <h3>[[mydata.title]] [[_isType('one')]]</h3>
        <template is="dom-if" if="[[_isType('one')]]"> <!-- problem is here -->
            <div>Should be displayed</div>
        </template>
    </template>

    <script>
        /**
        * @customElement
        * @polymer
        */
        class OhrBlock extends Polymer.Element {
            static get is() { return 'ohr-block'; }

            static get properties() {
                return {
                    mydata: {
                        type: Object,
                        value: {"title": "my title", "type" : "one"}
                    }
                };
            }

            _isType(type) {
                return this.mydata.type === type;
            }
        }

        window.customElements.define(OhrBlock.is, OhrBlock);
    </script>
</dom-module>

如您所見,我在h3 html標記中使用了[[_isType('one')]] 在這個地方它正在工作,我可以看到是true但是當我在條件屬性中使用[[_isType('one')]]類的條件if它不起作用並且模板內容也未顯示。

問題是我還沒有導入dom-if

<link rel="import" href="../bower_components/polymer/lib/elements/dom-if.html">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM