我有一个 Polymer 元素,用于<template is="dom-if"...
根据条件提供不同的 HTML 内容。
Polymerdom-if
没有 else 条件,因此需要一个否定的 if 条件来模拟它。
像这样的东西:
<link href="https://polygit.org/components/polymer/polymer.html" rel="import">
<dom-module id="test-thing">
<template>
<template is="dom-if" if="{{title}}" restamp>
<b>[[title]]</b>
</template>
<template is="dom-if" if="{{!title}}" restamp>
<i>no title</i>
</template>
</template>
<script>
Polymer({
is: 'test-thing',
properties: {
title: String
}
});
</script>
</dom-module>
<div>
With negative condition:
<test-thing></test-thing>
</div>
<div>
With positive condition:
<test-thing title="Has Title"></test-thing>
</div>
只有这样是行不通的——消极的条件永远不会过去。
这应该如何实施?