内容库操作
获取内容库详情
BaaS.ContentGroup.get(contentGroupID)
参数说明
请求示例
let contentGroupID = 1522726888567906
try {
let res = await BaaS.ContentGroup.get(contentGroupID)
// success
} catch (err) {
// err
}
let contentGroupID = 1522726888567906
BaaS.ContentGroup.get(contentGroupID).then(res => {
// success
}, err => {
// err
})
返回示例
res.data:
{
acl_gids: [ 9 ],
anonymous_read: false,
created_at: 1522726888,
id: 1522726888567906,
name: '资讯',
updated_at: 1548913710
}
获取内容库列表
BaaS.ContentGroup.find(options)
参数说明
options:
{{totalCount.withCountTips()}}
请求示例
try {
let res = await BaaS.ContentGroup.find({withCount: false})
// success
} catch (err) {
// err
}
BaaS.ContentGroup.find({withCount: false}).then(res => {
// success
}, err => {
// err
})
返回示例
res.data:
// withCount 为 false
{
meta: {
limit: 20,
next: null,
offset: 0,
previous: null,
},
objects: [
{
acl_gids: [ 9 ],
anonymous_read: false,
created_at: 1550471827,
id: 1550471827796573,
name: "新闻",
updated_at: 1559806752
},
{
acl_gids: [ 9 ],
anonymous_read: false,
created_at: 1550471301,
id: 1550471301605859,
name: "文章",
updated_at: 1550471301
}
]
}
// withCount 为 true
{
meta: {
limit: 20,
next: null,
offset: 0,
previous: null,
total_count: 2
},
objects: [
{
acl_gids: [ 9 ],
anonymous_read: false,
created_at: 1550471827,
id: 1550471827796573,
name: "新闻",
updated_at: 1559806752
},
{
acl_gids: [ 9 ],
anonymous_read: false,
created_at: 1550471301,
id: 1550471301605859,
name: "文章",
updated_at: 1550471301
}
]
}
以下操作都需指明操作的内容库,方法如下:
let MyContentGroup = new BaaS.ContentGroup(contentGroupID)
参数说明
MyContentGroup.getContent(richTextID)
参数说明
返回参数
info 如果有自定义字段,则一并返回
请求示例
let richTextID = 1514529306082815
MyContentGroup.getContent(richTextID).then(res => {
// success
}, err => {
// err
})
返回示例
res.data:
{
categories: [1513076252710475],
content: "<p>\b 该片讲述了伊娅不满父亲的恶作剧</p>",
cover: "https://cloud-minapp-1131.cloud.ifanrusercontent.com/1donykIpnuvcRiAX.jpg",
created_at: 1513076305,
created_by: 16042162,
description: "iphoneX 发布",
group_id: 1513076211190694,
id: 1513076305938456,
title: "iphone X",
updated_at: 1513076364
}
BaaS.ContentGroup#find(options)
参数说明
options:
{{totalCount.withCountTips()}}
请求示例
// 查找该内容库下的所有内容
MyContentGroup.find().then()
// 查找该内容库下在指定分类下的内容
let query = new BaaS.Query()
query.arrayContains('categories', [1513076252710475])
MyContentGroup.setQuery(query).find().then(res => {
// success
}, err => {
// err
})
MyContentGroup.getCategory(categoryID)
OBJECT 参数说明
返回参数
请求示例
let categoryID = 1513076252710475
MyContentGroup.getCategory(categoryID).then(res => {
// success
}, err => {
// err
})
返回示例
res.data:
{
have_children: true,
id: 1513076252710475,
name: "科技",
children: [
{
have_children: false,
id: 1514515552050186,
name: "评测"
}
]
}
BaaS.ContentGroup#getCategoryList(options)
参数说明
options:
{{totalCount.withCountTips()}}
请求示例
MyContentGroup.getCategoryList().then(res => {
// success
}, err => {
// err
})
分页与排序
请求示例
MyContentGroup.orderBy('-created_by').limit(5).offset(10).find().then()