在Polymer应用程序中查看以下html:
<paper-dialog id="confirmation" modal auto-fit-on-attach>
<h2><spring:message code="confirmation" /></h2>
<p>Are you sure ?<p>
<div class="buttons">
<paper-button dialog-confirm><spring:message code="yes" /></paper-button>
<paper-button dialog-dismiss><spring:message code="no" /></paper-button>
</div>
</paper-dialog>
以下JavaScript:
document.querySelector("#confirmation p").innerText = (message === undefined) ? "No message" : message;
document.getElementById("confirmation").toggle();
如何从对话框中获取'确认'的返回值?
答案 0 :(得分:4)
您通常会在对话框上为iron-overlay-closed
事件附加处理程序,以确定它是否为confirmed
,因为纸质对话框实现了PaperDialogBehavior。
类似于:
<template is="dom-bind" id="scope">
<paper-dialog id="confirmation" modal auto-fit-on-attach on-iron-overlay-closed="dismissDialog">
<h2><spring:message code="confirmation" /></h2>
<p>Are you sure ?<p>
<div class="buttons">
<paper-button dialog-confirm><spring:message code="yes" /></paper-button>
<paper-button dialog-dismiss><spring:message code="no" /></paper-button>
</div>
</paper-dialog>
</template>
<script>
(function() {
var scope = document.querySelector('#scope');
scope.dismissDialog = function(e) {
console.log(e.detail.confirmed);
if (e.detail.confirmed) {
// confirmed logic goes here
}
}
})();
</script>