apostrophe-cms - self.play 中没有加入的对象
问题描述
我的小部件用 加入了一个对象,但加入的对象在in 中joinByOne
不可用(只有它的 id)。虽然它是可用的。self.play
public/js/always.js
views/widget.html
// index.js
{
name: 'groups',
type: 'array',
schema: [
name: 'buildings',
type: 'array',
schema: [
{
name: '_building',
label: 'Building',
type: 'joinByOne',
withType: 'building',
required: true,
filters: {
projection: {
title:1,
latitude:1,
longitude:1,
_url: 1
}
}
}
]
]
}
正如预期的那样,views/widget.html
连接的对象可用。
// views/widget.html
<div class="map" data-groups='{{ data.widget.groups | jsonAttribute({ single:true }) }}'></div>
$('.map').data('groups')[0].buildings[0]._building
正如预期的那样,在浏览器控制台 中包含连接的对象。
self.play
另一方面,包含data.groups[0].buildings[0]
唯一的builgindId
,但没有实际的_building
.
// public/js/always.js
apos.define('map-widgets',{
extend: 'apostrophe-widgets',
construct: function(self,options) {
self.play = function($widget,data,options) {
console.log(data.groups[0].buildings[0])
}
}
})
这记录了一个包含buildingId
连接对象的对象,但没有_building
,即对象本身。
似乎连接没有data
在self.play
. 这是故意的吗?
如何访问连接的对象self.play
?
解决方案
Joins are filtered out of data
by default but you can override the filtering function per widget and essentially bypass the filtering.
In the index.js
of your widgets module
construct: function(self, options) {
// ... other stuff
self.filterForDataAttribute = function (widget) {
return widget;
};
}
推荐阅读
- javascript - Chrome 扩展程序 | 无法从内容脚本生成文件,Chrome GPUCache 文件夹呈指数增长
- hazelcast - 获取 hazelcast 集群中的所有 PN 计数器
- javascript - 在三个中将法线贴图添加到 bufferGeometry 形状
- python - Local Prefect 项目不会打印/记录结果
- javascript - 当多个匿名 Promise 评估时做某事
- php - Foreach 自定义循环
- javascript - 尝试将图像上传到 GraphCMS 时出现错误 400
- java - java - 如何使用java中的月日格式yyyy从dob计算年龄?前任。(1999 年 3 月 2 日)
- android - 如何在recyclerview android中的single_row_item的每个视图(imageView,textView)上添加不同的点击事件?
- javascript - 在受保护的路由中刷新时反应身份验证“失败”