【问题标题】:Modifying Angular Contentful API response修改 Angular Contentful API 响应
【发布时间】:2018-07-30 10:20:33
【问题描述】:

我有这样一个满足的服务..

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。您可以修改 api 调用并仅返回某些值,例如 modify api calls

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

但我不确定我将如何实现同样的事情,他们进行角度调用的方式。我可以只做一个 http 请求,但我更愿意保持与上面所做的相同的方式

任何帮助将不胜感激

【问题讨论】:

    标签: javascript angular typescript contentful


    【解决方案1】:

    您将select 属性添加到您的getEntries 调用中。

    // 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 sn-ps:https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/select-operator/query-entries/console/js

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多