我有这样的内容丰富的服务..
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>
但我不确定如何实现同样的事情,即他们进行 Angular 调用的方式。我可以只做一个 http 请求,但我更愿意保持与上面相同的方式
如有任何帮助,我们将不胜感激
最佳答案
您将 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 片段:https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/select-operator/query-entries/console/js
关于javascript - 修改 Angular Contentful API 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48878750/