我在访问纸张对话框中的纸张输入元素时遇到问题。我似乎不能获得纸张输入的值,而它在纸张对话框中,我只得到一个空值返回值。我知道有像this.$.element这样的东西,但我对如何实际使用它感到困惑。纸质对话框必须在自绑定模板中吗?
发布于 2015-04-29 05:46:23
一旦打开了一个文件对话框,它就会进入核心覆盖层的阴影中,从常规选择器中确定元素的作用域。如果对话框位于自动绑定模板内,则可以使用this.$.element语法访问其子对话框
<body>
<template id="app" is="auto-binding">
// other html content
<paper-dialog id="dialog">
<paper-input id="input"></paper-input>
</paper-dialog>
</template>
<script>
(function () {
var app = document.querySelector("#app");
app.addEventListener('template-bound', function () {
this.getValue = function () {
return this.$.input.value;
};
});
}());
</script>
</body>另一种选择是像以前一样使用自动绑定模板,并为输入值创建一个声明性变量
<body>
<template id="app" is="auto-binding">
// other html content
<paper-dialog id="dialog">
<paper-input value="{{inputValue}}"></paper-input>
</paper-dialog>
</template>
<script>
(function () {
var app = document.querySelector("#app");
app.addEventListener('template-bound', function () {
this.getValue = function () {
return this.inputValue;
};
});
}());
</script>
</body>使用自动绑定模板的一种方法是将对话框放在一个自定义元素中,并将其所有允许您使用这些方法的功能包含在其中。
我希望这能帮到你。
https://stackoverflow.com/questions/29925883
复制相似问题