【发布时间】:2018-11-28 20:41:20
【问题描述】:
我想知道如何从连接内的连接中获取数据。
例如:我有一个 category-widgets,它必须获取与所选类别相关的所有 课程 的信息(教师、描述和其他信息 -也加入了 课程 部分)。
module.exports = {
extend: 'apostrophe-widgets',
label: 'Categories',
addFields: [
{
name: '_category',
type: 'joinByArray',
withType: 'category',
label: 'Categories',
withJoins: ['_lesson'],
}
]
};
上面的代码是category-widgets的index.js。通过使用withJoins,我可以获取有关该课程的信息。
问题是课程本身主要由连接中的信息组成:
module.exports = {
extend: 'apostrophe-pieces',
name: 'lesson',
label: 'Lesson',
pluralLabel: 'Lessons',
addFields: [
{
name: '_teacher',
type: 'joinByArray',
withType: 'teacher',
label: 'Teacher(s)',
},
{
name: '_pill',
type: 'joinByArray',
withType: 'pill',
label: 'Pills of knowledge that make the lesson.',
},
]
};
我的问题是如何访问_teacher 中的数据和
_pill 在 category-widgets 的 widget.html 中。
apos.log(data.widget._category._lesson)输出正确的课程数据。但是当尝试从连接内部获取数据时:
apos.log(data.widget._category._lesson._teacher[0])输出 undefined。
【问题讨论】:
标签: apostrophe-cms