JS Buy SDK 已于 2025 年 1 月被弃用。 更多信息请参见 README

类:CollectionResource

CollectionResource()

JS Buy SDK 的集合资源

构造函数

new CollectionResource()

来源

方法

fetch(id) → {Promise|GraphModel}

根据 ID 获取商店中的单个集合,不包括产品。要获取包含产品的集合,请使用 fetchWithProducts。

参数
名称 类型 描述
id 字符串

要获取的集合的 ID。

来源
返回值

一个 promise,它解析为集合的 GraphModel

类型
Promise | GraphModel
示例
client.collection.fetch('Xk9lM2JkNzFmNzIQ4NTIY4ZDFiZTUyZTUwNTE2MDNhZjg==').then((collection) => {
  // Do something with the collection
});

fetchAll() → {Promise|Array.<GraphModel>}

获取商店中的所有集合,不包括产品。要获取包含产品的集合,请使用 fetchAllsWithProducts。

来源
返回值

一个 promise,它解析为集合的 GraphModel 数组。

类型
Promise | Array.<GraphModel>
示例
client.collection.fetchAll().then((collections) => {
  // Do something with the collections
});

fetchAllWithProducts() → {Promise|Array.<GraphModel>}

获取商店中的所有集合,包括产品。

来源
返回值

一个 promise,它解析为集合的 GraphModel 数组。

类型
Promise | Array.<GraphModel>
示例
client.collection.fetchAllWithProducts().then((collections) => {
  // Do something with the collections
});

fetchByHandle(handle) → {Promise|GraphModel}

根据 handle 获取商店中的集合。

参数
名称 类型 描述
handle 字符串

要获取的集合的 handle。

来源
返回值

一个 promise,它解析为集合的 GraphModel

类型
Promise | GraphModel
示例
client.collection.fetchByHandle('my-collection').then((collection) => {
  // Do something with the collection
});

fetchQuery(argsopt) → {Promise|Array.<GraphModel>}

获取商店中与查询匹配的所有集合。

参数
名称 类型 属性 描述
args 对象 <可选>

一个指定查询数据的对象,包含零个或多个

属性
名称 类型 属性 默认值 描述
first 整数 <可选>
20

中继 first 参数。这指定页面大小。

sortKey 字符串 <可选>
ID

用于对结果排序的键。 可用值记录为 集合排序键

query 字符串 <可选>

查询字符串。 请参阅此处的完整文档:此处

reverse 布尔值 <可选>

是否反转结果的排序顺序

来源
返回值

一个 promise,它解析为集合的 GraphModel 数组。

类型
Promise | Array.<GraphModel>
示例
client.collection.fetchQuery({first: 20, sortKey: 'CREATED_AT', reverse: true}).then((collections) => {
  // Do something with the first 10 collections sorted by title in ascending order
});

fetchWithProducts(id) → {Promise|GraphModel}

根据 ID 获取商店中的单个集合,包括产品。

参数
名称 类型 描述
id 字符串

要获取的集合的 ID。

来源
返回值

一个 promise,它解析为集合的 GraphModel

类型
Promise | GraphModel
示例
client.collection.fetchWithProducts('Xk9lM2JkNzFmNzIQ4NTIY4ZDFiZTUyZTUwNTE2MDNhZjg==').then((collection) => {
  // Do something with the collection
});