const View = require('dmp-new/view') module.exports = View.extend({ tmpl: '@category.html', init () { }, async render () { const articles = await this.getData() this.updater.digest({ articles }) }, async getData () { try { // 获取一级目录 const models = [{ name: 'api_directory_getTree_get', dataType: 'jsonp', params: { id: 144 } }] const [model] = await this.fetch(models) const childs = model.get('data.node.child', []) // 获取二级目录,每一很篇文章都放在一个二级目录下 const childModels = [] for (const child of childs) { childModels.push({ name: 'api_commoncontent_findContents_get', dataType: 'jsonp', params: { nodeId: child.id, perPageSize: 30, toPage: 1 } }) } const respModels = await this.fetch(childModels) const articles = [] for (const resp of respModels) { const art = resp.get('data.list', [])[0] articles.push(art) } return articles } catch (error) { this.alert('错误提示', error.msg || error.message) } } })