首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修改Angular Contentful API响应

修改Angular Contentful API响应
EN

Stack Overflow用户
提问于 2018-02-20 13:56:56
回答 1查看 248关注 0票数 0

我有一个满意的服务,就像这样..

代码语言:javascript
复制
import { Injectable } from '@angular/core';
import { createClient, Entry } from 'contentful';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';


const CONFIG = {
   space: '<spaceid>',
   accessToken: '<accesstoken>',

   contentTypeIds: {
      programItems: 'programItem'
   }
};

@Injectable()
export class ContentfulService {
private cdaClient = createClient({
    space: CONFIG.space,
    accessToken: CONFIG.accessToken
});

public weekNumber = new BehaviorSubject<any>(1);

constructor() { }
// Get all the program items
getProgramItems(query?: object): Promise<Entry<any>[]> {
   return this.cdaClient.getEntries(Object.assign({
     content_type: CONFIG.contentTypeIds.programItems
   }, query))
   .then(res => res.items);
}

}

但我只想在内容丰富的文档中引入programItems sys.ids。您可以修改应用程序接口调用并仅返回某些值,如下面的modify api calls

https://cdn.contentful.com/spaces/<space_id>/entries/ ?select=fields.productName,fields.price &content_type=<content_type_id>

但我不确定我将如何实现同样的事情,就像他们做angular调用的方式一样。我可以只做一个http请求,但我更喜欢保持与上面相同的方式。

任何帮助都将不胜感激

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-20 15:14:27

您可以向getEntries调用添加一个select属性。

代码语言:javascript
复制
// Get all the program items
getProgramItems(query?: object): Promise<Entry<any>[]> {
   return this.cdaClient.getEntries(Object.assign({
     content_type: CONFIG.contentTypeIds.programItems,
     select: 'sys.id'
   }, query))
   .then(res => res.items);
}

您可以在此处阅读完整的文档,包括javascript代码片段:https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/select-operator/query-entries/console/js

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48878750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档