【发布时间】:2019-10-29 19:34:10
【问题描述】:
假设我们创建了一个简单的小部件,它可能有一个字符串或一个富文本字段。当我将小部件插入 html 时,我想指定哪个字段是可见/活动的。换句话说,我想为小部件添加一些自定义选项,这将改变它的行为。 小部件如下所示:
{{
apos.singleton(data.page, 'footerTitle', 'footerTitle', {
controls: {
movable: false,
position: 'top-right'
}
})
}}
我想做这样的事情:
{{
apos.singleton(data.page, 'footerTitle', 'footerTitle', {
controls: {
movable: false,
position: 'top-right'
},
settings: {
type: 'string',
anotherParameter: 1,
thirdParameter: false
}
})
}}
稍后(在小部件的 index.js 中)将相应地处理这些参数:
...
beforeConstruct: function( self, options )
{
if (type === 'string')
{
// Do some additional setup, magic, whatever...
}
switch (anotherParamter)
{
// Add some insane code here :)
}
},
construct: function( self, options )
{
const superLoad = self.load;
self.load = ( req, widgets, callback ) => superLoad( req, widgets, ( err ) =>
{
if( err )
{
return callback( err );
}
for( const widget of widgets )
{
// Some additional work here based on the initial settings.
}
return callback( null );
} );
}
...
是否有可能向小部件添加自定义参数、选项(在 2.98.1 版或更高版本的 3.0.0 中)?
【问题讨论】:
标签: apostrophe-cms