假设我们创建了一个简单的小部件,其中可能包含字符串或RTF字段。当我将小部件插入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中?)>
假设我们创建了一个简单的小部件,其中可能包含字符串或RTF字段。当我将小部件插入html时,我想指定哪个字段是可见/活动的。换句话说,我想...
这不可能像您在Apostrophe 2.x中显示的那样,因为小部件选项是从模板传递的,并且模板只能执行同步工作。小部件模块的load
方法已在这一点上运行。所以现在影响事物的获取为时已晚。