1 Star 0 Fork 34

lvhaiyan888/outline.js

forked from Yaohaixiao/outline.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
_getChaptersWithCode.js 740 Bytes
一键复制 编辑 原始数据 按行查看 历史
import isArray from './utils/types/isArray'
const _getChaptersWithCode = (chapters) => {
const groups = {}
const cb = (o) => {
return [o.pid]
}
chapters.forEach((o) => {
const group = JSON.stringify(cb(o))
groups[group] = groups[group] || []
groups[group].push(o)
o.index = groups[group].length
if (o.pid === -1) {
o.code = String(o.index)
}
})
Object.keys(groups).forEach((group) => {
groups[group].forEach((c) => {
const subjects = groups[`[${c.id}]`]
if (!subjects || !isArray(subjects)) {
return false
}
subjects.forEach((o) => {
o.code = c.code + '.' + o.index
})
})
})
return chapters
}
export default _getChaptersWithCode
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/lvhaiyan/outline.js.git
[email protected]:lvhaiyan/outline.js.git
lvhaiyan
outline.js
outline.js
master

搜索帮助