0
dom-if
模板不起作用。我有以下聚合物2成分:dom-if模板不起作用
<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>
正如你所看到的,我使用[[_isType('one')]]
內h3
HTML標記。在這個地方,它正在工作,我可以看到true
但是當我使用[[_isType('one')]]
類似條件if
屬性它不起作用,並且不顯示模板內容。