在Polymer

时间:2016-08-01 20:08:51

标签: javascript ajax polymer polymer-1.0

我遇到一个问题,即ajax请求没有更新UI。我需要手动刷新页面。

基本上它就像一个按钮。按下时,应增加喜欢的数量。 HTTP请求和响应正常工作。但值{{commentaire.likes}}不会立即更新。

<template>
    <form is="iron-form" id="likeForm" method="post" action="/like/{{commentaire.heure}}" on-click="submitLike" on-iron-form-response="augmenterLikes">
        <paper-button raised>{{commentaire.likes}} J'aime</paper-button>        
    </form>

</template>

<script>


    Polymer({

        is: 'my-comment',
        properties: {
            commentaire : {
                type: Object,
                value: {},                  
            },
        }, 

        augmenterLikes: function(e) {
            this.commentaire.likes = e.detail.response;
        },



    });

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

要更新深层属性,您必须使用set方法,例如在您的情况下:

this.set('commentaire.likes', e.detail.response);

我在这里使用随机数生成器做了一个例子:https://jsfiddle.net/fLbf6uag/1/