内容分类操作

以下操作都需指明操作的内容库,方法如下:

let MyContentCategory = new BaaS.ContentCategory(contentGroupID)

参数说明

参数类型必填说明
contentGroupIDNumber内容库 ID

创建内容分类

MyContentCategory.create({name, parent})

参数说明

参数类型必填说明
nameString内容分类名称
parentNumber父分类 ID

返回参数

参数类型说明
subcategoriesNumber Array子内容分类
parentObject父分类对象
idNumber内容分类 ID
nameString内容分类名称
created_atNumber创建时间
update_atNumber更新时间

请求示例

  1. MyContentCategory.create({name: 'test category', parent: parentID}).then(res => {
  2. // success
  3. }, err => {
  4. // err
  5. })

返回示例

res.data:

  1. {
  2. "created_at": 1536836590,
  3. "id": 1536836590938566,
  4. "name": "test catetory",
  5. "parent": {
  6. "id": 1536748828013607,
  7. "name": "name-fdsaer"
  8. },
  9. "subcategories": [],
  10. "updated_at": 1536836590
  11. }

获取内容分类详情

MyContentCategory.get(categoryID)

参数说明

参数名类型必填说明
categoryIDNumber内容分类 ID

返回参数

参数类型说明
subcategoriesNumber Array子内容分类
created_atNumber创建时间
parentObject父分类对象
idNumber内容分类 ID
nameString内容分类名称
update_atNumber更新时间

请求示例

  1. MyContentCategory.get(categoryID).then(res => {
  2. // success
  3. }, err => {
  4. // err
  5. })

返回示例

res.data:

  1. {
  2. "created_at": 1536836590,
  3. "id": 1536836590938566,
  4. "name": "test catetory",
  5. "parent": {
  6. "id": 1536748828013607,
  7. "name": "name-fdsaer"
  8. },
  9. "subcategories": [],
  10. "updated_at": 1536836590
  11. }

获取内容分类总数

BaaS.ContentCategory#count()

  1. let num = await MyContentCategory.count()
  2. console.log(num) // 10
  1. MyContentCategory.count().then(num => {
  2. // success
  3. console.log(num) // 10
  4. callback(null, res)
  5. }, err => {
  6. // err
  7. callback(err)
  8. })

查询,获取内容分类列表

BaaS.ContentCategory#find(options)

参数说明

options:

参数类型必填默认说明
withCountbooleantrue是否返回 total_count

withCount 设为 false,接口返回的数据中不包含 total_count,当数据条目多时,可通过不返回 total_count 提高响应速度。如果需要查询记录的总数,请使用 count 方法。

SDK v2.x withCount 的默认值为 true,SDK v3+ withCount 的默认值为 false

排序

内容分类查询排序与数据表排序方法一致,但只支持对以下指定字段进行排序:

支持字段描述
created_at内容分类创建时间
updated_at内容分类更新时间

分页

内容分类查询排序与数据表分页方法一致。

请求示例

  1. MyContentCategory.offset(0).limit(10).orderBy('-created_at').find().then(res => {
  2. // success
  3. }, err => {
  4. // err
  5. })

更新内容分类

MyContentCategory.update(categoryID, {name, parent})

参数说明

参数类型必填说明
categoryIDNumber内容分类 ID
nameString内容分类名称
parentNumber父分类 ID

返回参数

参数类型说明
subcategoriesNumber Array子内容分类
parentObject父分类对象
idNumber内容分类 ID
nameString内容分类名称
created_atNumber创建时间
update_atNumber更新时间

请求示例

  1. MyContentCategory.update(categoryID, {
  2. name: 'category-name-new',
  3. parent: parentID,
  4. }).then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })

返回示例

res.data:

  1. {
  2. "created_at": 1536748828,
  3. "id": 1536748828013607,
  4. "name": "category-name-new",
  5. "parent": null,
  6. "subcategories": [],
  7. "updated_at": 1536844892
  8. }

删除内容

MyContentCategory.delete()

参数说明

参数类型必填说明
categoryIDNumber内容分类 ID

请求示例

  1. MyContentCategory.delete(categoryID).then(res => {
  2. // success
  3. }, err => {
  4. // err
  5. })

返回示例

res.data:

  1. ""