首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >聚合物铁型,进入时提交两次

聚合物铁型,进入时提交两次
EN

Stack Overflow用户
提问于 2016-03-02 20:06:30
回答 1查看 237关注 0票数 0

在聚合物中处理注释元素,当用户按enter键时,应该提交注释。enter部件可以工作,但是注释被提交了两次,造成了重复。你能说出什么不对吗?谢谢!

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-02 20:13:18

通过向setInterval函数中添加一个sendComment来解决这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35757062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档