Javascript 知足的+;角2
嗨,我正在尝试使用Contentful和Angular2,并使用Contentful交付API 例如,我可以获得特定的数据 知足的服务Javascript 知足的+;角2,javascript,angular,angular2-services,contentful,Javascript,Angular,Angular2 Services,Contentful,嗨,我正在尝试使用Contentful和Angular2,并使用Contentful交付API 例如,我可以获得特定的数据 知足的服务 HomePage() { return this.http .get('https://cdn.contentful.com/spaces/PRIVATE/entries?access_token=PRIVATE&sys.id=PRIVATE') .map((res:Response)
HomePage() {
return this.http
.get('https://cdn.contentful.com/spaces/PRIVATE/entries?access_token=PRIVATE&sys.id=PRIVATE')
.map((res:Response) => res.json()); /* map response to var */
}
homepage.component.ts
export class Home {
pagename: string;
ngOnInit() {
this.http.HomePage()
.subscribe(
data => {
this.pagename = data.items[0].fields.pageName;
}
);
}
}
但是,如果我有多个项,我需要将每个data.item声明为一个字符串,这将非常冗长。然后,如果我决定向内容类型添加一个新字段,这可能会添加到数组的中间,这样就破坏了当前的绑定,并且需要再次更新它们。
我见过另一个回购协议,他们在模板中使用了我正在寻找的架构,我知道这是做我需要做的事情的正确方法
e、 g.homepage.template.html
<ul contentful-entries="'content_type=dog&limit=10'">
<li ng-repeat="dog in $contentfulEntries.items">
{{ dog.fields.name }}
</li>
</ul>
我假设通过查找您需要的项目的ID,然后查找任何关系,您会得到资产的ID,然后查找资产?但这又是通过SDK实现的吗?还是我需要写这个代码
我迷路了
非常感谢您的帮助,谢谢 我在Contoful工作,负责JS SDK 我在这里看到了一些解决方案:
哈立德嘿,这方面有什么更新吗?现在有什么例子吗?有一个关于如何做到这一点的教程
{
"sys": {
"type": "Array"
},
"total": 1,
"skip": 0,
"limit": 100,
"items": [
{
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "1ST_UNIQUE_ID"
}
},
"id": "2ND_UNIQUE_ID",
"type": "Entry",
"createdAt": "2016-07-14T16:30:12.787Z",
"updatedAt": "2016-07-14T16:30:12.787Z",
"revision": 1,
"contentType": {
"sys": {
"type": "Link",
"linkType": "ContentType",
"id": "pressRelease"
}
},
"locale": "en-US"
},
"fields": {
"title": "Title of Review",
"excerpt": "Excerpt of review",
"content": "Content of Review",
"dateCreated": "2016-07-01",
"datePublished": "2016-07-14",
"featureImage": {
"sys": {
"type": "Link",
"linkType": "Asset",
"id": "3RD_UNIQUE_ID"
}
}
}
}
],
"includes": {
"Asset": [
{
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "1ST_UNIQUE_ID"
}
},
"id": "4TH_UNIQUE_ID",
"type": "Asset",
"createdAt": "2016-07-14T16:30:05.078Z",
"updatedAt": "2016-07-14T16:30:05.078Z",
"revision": 1,
"locale": "en-US"
},
"fields": {
"title": "Image Title",
"description": "Image Description",
"file": {
"url": "//url-of-image.jpg",
"details": {
"size": 43098,
"image": {
"width": 1278,
"height": 928
}
},
"fileName": "image.jpg",
"contentType": "image/jpeg"
}
}
}
]
}
}