【发布时间】:2018-06-12 10:48:30
【问题描述】:
我正在尝试使用 Polymer 中的按钮隐藏/取消隐藏 UI 元素,但它不起作用。我有按钮和元素:
<button id="runPredictionButton">
<i>Button text</i>
</button>
<px-card
hidden$="{{hide}}">
//...content here
</px-card>
<div class="output"></div>
我也定义了属性和事件监听器:
<script>
Polymer({
is: 'custom-view',
properties: {
hide: {
type: Boolean,
value: false
},
},
ready: function() {
var self = this;
this.$.runPredictionButton.addEventListener('click', function() {
if (some_conditon == true) {
filerootdiv.querySelector('.output').innerHTML = 'Is true';
this.hide = true
console.log("This hide should be true:" + this.hide);
}
else {
filerootdiv.querySelector('.output').innerHTML = 'Is false';
this.hide = false
console.log("This hide should be false:" + this.hide);
}
});
}
});
</script>
我确信some_conditon 有效,因为.output 元素的内容确实发生了变化,但是px-card 元素根本没有隐藏/取消隐藏。此外,在控制台上我可以看到 this.hide 已更改为所需的值,但无论如何该元素都保持隐藏状态。我需要做些什么/自动强制更新内容吗?为什么这不起作用?如何通过更改hide 变量来确保隐藏px-card 元素?
【问题讨论】:
标签: html node.js polymer polymer-1.0