首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于铁数据表的问题

关于铁数据表的问题
EN

Stack Overflow用户
提问于 2017-04-24 16:23:20
回答 1查看 85关注 0票数 0

我对来自聚合物的动态表格组件有一些问题。下面是我想要实现的目标:我希望发送带有ajax请求的sql请求,并使用该请求的响应更新表。

到目前为止,我所做的是发送我的sql请求,然后服务器使用数据创建一个.json文件,然后使用另一个请求来获取该文件并将其放入表中。

问题是,我必须刷新整个网页,才能填满表格。

有没有办法直接用第一个ajax请求的响应来更新表,而不使用json文件呢?

这是我的代码:

代码语言:javascript
复制
<template>
    <iron-ajax 
    id="request" 
    url="/request" 
    method="POST" 
    on-response="ajaxResult"
    on-error="ajaxError"
    content-type="application/json"
    body: {id, Prio, Stat}></iron-ajax>

<iron-ajax url="../data.json" last-response="{{data}}" auto></iron-ajax>

<iron-data-table items="[[data]]" id="table123">
<data-table-column name="Title">
    <template>[[item.ID]]</template>
</data-table-column>
<data-table-column name="PRIORITY">
    <template>[[item.PRIORITY]]</template>
</data-table-column>
<data-table-column name="REQUEST_STATUS">
    <template>[[item.REQUEST_STATUS]]</template>
</data-table-column></iron-data-table>

</template>

<script>
    Polymer({
        is: 'gestion-ticket',

    ajaxResult: function(e) {
        //var Object=e.detail.response;
        document.getElementById("table123").clearCache();

    },
    f: function(e) {
        var body = {
        "id": this.querySelector("#comment").value,
        "Prio" : this.querySelector("#Priority").selected,
        "Stat" : this.querySelector("#Status").selected
        };
        this.$.request.body = body;
        this.$.request.generateRequest();
        },
    ajaxError: function(event) {
        console.log(event);
        console.log(event.detail);
        console.log(event.detail.request);
        console.log(event.detail.request.xhr.response);
    }
    });
</script>

我尝试了clearCache()函数来重置,但它不起作用,我觉得这是我应该使用的函数,但我在这里做了其他错误的事情。非常感谢你抽出时间来帮助我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-24 17:16:27

以下是如何正确发送AJAX请求、接收响应和将接收到的数据绑定到铁数据表:

代码语言:javascript
复制
 <iron-ajax 
        method="POST"
        handle-as="json"
        id="iron_ajax_element"
        on-response="recieve_responseHandler"
        ></iron-ajax>

 .....

    send_request: function() {

            console.log('send_request:');

            var iron_ajax_element = this.$.iron_ajax_element;


            //set AJAX URL point
            iron_ajax_element.url = this.some_url;

            //set AJAX params
            var aniArgs = {};
            aniArgs['param'] = this.some_param;
            iron_ajax_element.params = aniArgs;

            //run AJAX
            iron_ajax_element.generateRequest();
    },
    recieve_responseHandler: function(e) {

        console.log('recieve_responseHandler:');

        console.log(e.detail.response);
        var response  = e.detail.response;
        console.log(response);

       //Bind the response to iron-data-table here, as:
       this.iron_data = response;

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

https://stackoverflow.com/questions/43593243

复制
相关文章

相似问题

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