首页 > 解决方案 > self.play 中没有加入的对象

问题描述

我的小部件用 加入了一个对象,但加入的对象在in 中joinByOne不可用(只有它的 id)。虽然它是可用的。self.playpublic/js/always.jsviews/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

解决方案


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;
   };
}

推荐阅读