我有一个CKEditor自定义插件我正在尝试编写,但需要一些帮助来确定如何从“活动”选项卡的下拉框中插入值。
我有4个标签,每个标签都有自己的下拉列表。当用户选择选项卡,然后在下拉列表中选择一个值,然后按“确定”按钮,我希望将“活动选项卡”下拉列表的当前值插入到文档中。
下面的代码正在努力做到这一点,除了我必须硬编码我想从中获取信息的选项卡。请参阅:“onOk”事件的abbr.setText( dialog.getValueOf( 'tab1', 'tenant_dropdown' ) );
。我想要更像这样的东西:abbr.setText( dialog.getValueOf( activeTab, activeElement ) );
或类似的东西......我找不到这方面的文件......我是愚蠢的吗?
我有什么想法可以做到这一点?谢谢你的帮助。
继承我的插件代码:
CKEDITOR.plugins.add( 'rz_db',
{
requires : ['richcombo'], //, 'styles' ],
init : function( editor )
{
editor.addCommand( 'abbrDialog', new CKEDITOR.dialogCommand( 'abbrDialog' ) );
editor.ui.addButton( 'Rz Database Field',
{
label: 'Insert Rz Database Field',
command: 'abbrDialog',
icon: this.path + 'images/icon.png'
} );
CKEDITOR.dialog.add( 'abbrDialog', function ( editor )
{
var tenant_fields = []; //new Array();
tenant_fields[0]=["First Name", "$RZ{tenant_first_name}"];
tenant_fields[1]=["Last Name", "$RZ{tenant_first_name}"];
tenant_fields[2]=["Address", "$RZ{tenant_address}"];
return {
title : 'Rz Database Fields',
minWidth : 400,
minHeight : 200,
contents :
[
{
id : 'tab1',
label : 'Tenants',
elements :
[
{
id : 'tenant_dropdown',
type : 'select',
label : 'Select the field you want, then press the "OK" button to insert it into the document.',
'default':'',
items: tenant_fields,
onChange : function( api ) {
// this = CKEDITOR.ui.dialog.select
alert( 'Current value: ' + this.getValue() );
}
}
]
},
{
id : 'tab2',
label : 'Owners',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
},
{
id : 'tab3',
label : 'Vendors',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
},
{
id : 'tab4',
label : 'Other',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
}
],
onOk : function()
{
var dialog = this;
var abbr = editor.document.createElement( 'rz_db' );
abbr.setText( dialog.getValueOf( 'tab1', 'tenant_dropdown' ) );
editor.insertElement( abbr );
}
};
} );
}
});
答案 0 :(得分:1)
答案 1 :(得分:0)
我有相同的情况并找到以下解决方案 - 此方法getContentElement返回有关该元素的整个数据,之后获取字段值可以使用getValue()方法。
var s = this.getDialog(),
z = s.getContentElement('tab1', 'tenant_dropdown'),
val = z.getValue(); // Get field value