我在 Heroku 免费帐户(expressJS) url 上运行的 api 端点在这里
它显示了来自 expressJS 路由的 json 响应。数据看起来像这样
[{"_id":"5938b81bd263a5144c9d7d17","title":"mlab first entry","__v":0},
{"_id":"5939efc7fac2b71aac4add11","title":"Second Entry","__v":0},
{"_id":"5939efd0fac2b71aac4add12","title":"Second Entry","__v":0}]
我从本地主机运行的聚合物代码(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>
`
但是当我访问我的聚合物页面时,它没有显示任何数据......我做错了什么?
这是我的路线代码:
router.get('/', function(req, res){
Comment.find(function(err, comments){
res.json(comments);
});
});
我需要格式化服务器 res.json 吗?还是使用 res.format(object)?我很感激这里的任何帮助。