已加入对象在self.play中不可用

问题描述 投票:0回答:1

我的窗口小部件使用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,即对象本身。

[似乎在dataself.play中可用的对象中未执行连接。这是故意的吗?

如何在self.play中访问已连接的对象?

apostrophe-cms
1个回答
0
投票

默认情况下,联接是从data中过滤出来的,但是您可以覆盖每个小部件的过滤功能,并实际上绕过过滤。

在小部件模块的index.js

construct: function(self, options) {
   // ... other stuff
   self.filterForDataAttribute = function (widget) { 
      return widget;
   };
}
© www.soinside.com 2019 - 2024. All rights reserved.