我的小部件使用joinByOne联接一个对象,但是联接的对象在public/js/always.js中的self.play中不可用(只有它的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,即对象本身。
连接似乎没有在self.play的data中可用的对象中执行。这是故意的吗?
如何在self.play中访问连接的对象
发布于 2019-09-26 03:05:06
默认情况下,连接会从data中过滤掉,但您可以覆盖每个小部件的过滤函数,并从本质上绕过过滤。
在小部件模块的index.js中
construct: function(self, options) {
// ... other stuff
self.filterForDataAttribute = function (widget) {
return widget;
};
}https://stackoverflow.com/questions/58092940
复制相似问题