铁数据问题 table
Issues with iron data table
我对来自 Polymer 的动态 tables 组件有一些问题。这是我想要实现的目标:我想发送一个带有 ajax 请求的 sql 请求,并使用该请求的响应更新 table。
到目前为止,我设法做的是发送我的 sql 请求,然后服务器创建一个包含数据的 .json 文件,然后我使用另一个请求来获取该文件并将其放入 table.
问题是我必须刷新整个网页才能填充 table。
有没有什么方法可以直接用第一个 ajax 请求的响应更新 table,而不是使用 json 文件?
这是我的代码:
<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() 函数来重置,但它不起作用,我觉得这是我应该使用的函数,但我在这里做错了。非常感谢您抽出时间来帮助我。
以下是如何正确发送 AJAX 请求、接收响应并将接收到的数据绑定到 Iron 数据 table:
<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;
},
我对来自 Polymer 的动态 tables 组件有一些问题。这是我想要实现的目标:我想发送一个带有 ajax 请求的 sql 请求,并使用该请求的响应更新 table。
到目前为止,我设法做的是发送我的 sql 请求,然后服务器创建一个包含数据的 .json 文件,然后我使用另一个请求来获取该文件并将其放入 table.
问题是我必须刷新整个网页才能填充 table。
有没有什么方法可以直接用第一个 ajax 请求的响应更新 table,而不是使用 json 文件?
这是我的代码:
<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() 函数来重置,但它不起作用,我觉得这是我应该使用的函数,但我在这里做错了。非常感谢您抽出时间来帮助我。
以下是如何正确发送 AJAX 请求、接收响应并将接收到的数据绑定到 Iron 数据 table:
<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;
},