问题
My api end point which running on Heroku free account(expressJS) url IS HERE
It shows json response from an expressJS route. The data looks like this
[{"_id":"5938b81bd263a5144c9d7d17","title":"mlab first entry","__v":0},
{"_id":"5939efc7fac2b71aac4add11","title":"Second Entry","__v":0},
{"_id":"5939efd0fac2b71aac4add12","title":"Second Entry","__v":0}]
My polymer code which I run from localhost(http://127.0.0.1:8081/view1):`
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="shared-styles.html">
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
<dom-module id="my-view1">
<template>
<iron-ajax
auto
url="https://shielded-caverns-24265.herokuapp.com/"
handle-as="json"
last-response="{{response}}">
</iron-ajax>
<<!--tried items={{response}} -->
<template is="dom-repeat" items="[[response.title]]">
<div>
<a href="{{item.title}}">     {{ item.title}}</a>
</div>
</template>
<!-- this code works and pull the data from https://reqres.in/api/users?page=2
<template is="dom-repeat" items="[[response.data]]">
<div>
<a href="{{item.first_name}} {{item.last_name}}"> {{item.first_name}}     {{ item.last_name}}</a>
</div>
</template>
-->
</template>
<script>
class MyView1 extends Polymer.Element {
static get is() { return 'my-view1'; }
}
window.customElements.define(MyView1.is, MyView1);
</script>
</dom-module>
`
But when I visit my polymer page, it is not showing any data...What am I doing wrong?
Here is my route code:
router.get('/', function(req, res){
Comment.find(function(err, comments){
res.json(comments);
});
});
Do I need to format the server res.json? Or use res.format(object)? I appreciate any help here.
来源:https://stackoverflow.com/questions/44459901/polymer-iron-ajax-get-method-retrieving-result-from-an-expressjs-route-returning