2016-03-02 59 views
0

处理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

通过向sendComment函数添加setInterval来解决此问题。