応答ハンドラー関数を実行しないでください。理由がわかりません
紙の要素の外側で、document.getelemetbyid() を使用して応答を行いますが、それを紙の要素に入れると何もしません。
これが私のコードです:
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/core-ajax/core-ajax.html">
<polymer-element name="post-service" attributes="posts">
<template>
<style>
:host {
display: none;
}
</style>
<core-ajax auto url="http://yami-no-seire.hol.es/blog/api/get_recent_posts/" on-core-response="{{postsLoaded}}" handleAs="json">
</core-ajax>
</template>
<script>
Polymer({
created: function () {
this.posts = [];
},
/*AJAX Success Callback Method*/
postsLoaded: function() {
console.log("Ok");
var respuesta = this.$.ajax
/*document.querySelector('#student-table-template').model = {
posts: e.detail.response
};*/
var data = respuesta.detail.response.posts,
posts = [],
el = document.createElement("div");
// build custom object
for (var i = 0; i < data.length; i++) {
//escape title
el.innerHTML = data[i].title;
var title = el.innerHTML;
//escape content
el.innerHTML = data[i].excerpt;
var excerpt = el.innerHTML;
entradas.push({
url: data[i].url,
title: title,
excerpt: excerpt.replace(' ', ' ').replace('<p>', '').replace('</p>', ''),
modified: parseDate(data[i].modified),
name: data[i].author.name
});
}
this.posts = posts;
}
});
function parseDate(date) {
var d = new Date(date);
var months = ["January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December"
];
return d.getDate() + " - " + months[d.getMonth()] + " - " + d.getFullYear();
};
</script>
</polymer-element>
core-ajax がリクエストを処理しないようです。