好的。所以我上一个帖子太模棱两可了。对于我的第二篇文章,让我尝试以更直截了当的方式解决同样的问题。下面是代码。这是我得到的结果的屏幕截图。关于第二个 Iron-ajax 调用,如果我在终端中使用 curl 和 this () 我得到我想要的(它是一个链接预览服务,所以标题、img、desc 等)。尝试使用按照规范定义的所需参数的 Iron-ajax 帖子来完成相同的任务。我没有收到任何控制台错误(第一次),并且根据我在第二个 dom-repeat 正文中输出最后响应变量时得到的 [object.Object] 结果,似乎正在返回一个 json 对象就像第一个 iron-ajax 调用(它确实有效,包括链接但没有足够的数据,因此通过返回我想要显示的数据的第二个服务运行链接)。
代码:
<dom-module id="my-new-view">
<template>
<!-- Defines the element's style and local DOM -->
<style>
:host {
display: block;
padding: 16px;
}
</style>
<iron-ajax auto
url="https://api.rss2json.com/v1/api.json?rss_url=http://feeds.feedburner.com/DrudgeReportFeed"
params="{"fmt":"xml-rss"}"
handle-as="json"
last-response="{{ajaxResponse}}"></iron-ajax>
<p>First: {{ajaxResponse}}</p>
<template is="dom-repeat" items="[[ajaxResponse.items]]" as="item" index-as="item_no">
<p>{{item.title}}</p>
<iron-ajax auto
method="post"
url="https://guteurls.de/api/"
params="{"u":"{{item.guid}}", "r":"https://127.0.0.1", "e":"s652imb8et42xd0bd", "t":"json"}"
handle-as="json"
last-response="{{newAjaxResponse}}"></iron-ajax>
<p>Second: {{newAjaxResponse}}</p>
<template is="dom-repeat" items="[[newAjaxResponse.newItems]]" as="newItem" index-as="newItem_no">
<p>{{newItem.title}}</p>
<paper-card heading="{{newItem.title}}" image="{{newItem.image.url}}" alt="{{newItem.title}}">
<div class="card-content">
<h1>Description: {{newItem.desc}}</h1>
<p>Test</p>
</div>
<div class="card-actions">{{newItem.title}}
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</template>
</template>
</template>
<script>
class MyNewView extends Polymer.Element {
static get is() { return 'my-new-view'; }
}
customElements.define(MyNewView.is, MyNewView);
</script>
</dom-module>