我的窗口小部件使用joinByOne
连接了一个对象,但是在self.play
中的public/js/always.js
中,该连接的对象不可用(仅其ID)。它在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
中访问已连接的对象?
默认情况下,联接是从data
中过滤出来的,但是您可以覆盖每个小部件的过滤功能,并实际上绕过过滤。
在小部件模块的index.js
中
construct: function(self, options) {
// ... other stuff
self.filterForDataAttribute = function (widget) {
return widget;
};
}