繁体   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