处理Polymer中的注释元素,其中注释应在用户按Enter键时提交。输入部分有效,但评论提交两次,导致重复。你能说出什么错吗?谢谢!
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/paper-input/paper-input.html">
<link rel="import" href="/bower_components/iron-form/iron-form.html">
<link rel="import" href="/bower_components/iron-input/iron-input.html">
<link rel="import" href="/bower_components/iron-a11y-keys/iron-a11y-keys.html">
<dom-module is="post-comments">
<template>
<div class="wrapper">
<div class="comment-input-wrapper">
<iron-a11y-keys id="a11y" keys="enter" target="[[target]]"
on-keys-pressed="sendComment" stopKeyboardEventPropagation="true"></iron-a11y-keys>
<form is="iron-form" method="get" action="/ajax/group/comment.php" id="commentForm">
<input is="iron-input" type="text" name="comment" placeholder="Kommenter..." value="{{commentInput::input}}" class="comment_input" id="currentComment">
<input type="hidden" name="post_id" value="{{postId}}">
</form>
</div>
</div>
</template>
<script>
Polymer({
is: "post-comments",
properties: {
postId: {
type: Number
},
commentInput: {
type: String,
notify: true
},
target: {
type: Object,
value: function() {
return this.$.currentComment;
}
}
},
listeners: {
'iron-form-response': 'displayMessage'
},
sendComment: function(e) {
this.$.commentForm.submit();
},
displayMessage: function(e) {
//Display response
}
});
</script>
</dom-module>
答案 0 :(得分:0)
通过向sendComment函数添加setInterval解决了这个问题。