正在尝试弄清楚如何动态填充对话框中的选择菜单...到目前为止,在我所有的尝试中,我都没能让它正常工作。
发布于 2011-07-27 22:29:25
我认为你正在尝试做的是在你的插件中动态地填充一个下拉列表。无论出于什么原因,都需要在对话框打开时填充该下拉列表。
如果是这样,下面是我针对类似情况所做的工作:
{
type: 'select',
id: 'exam_ID',
label: 'Select Exam',
items : [ ['--- Select an Exam---',0] ],
setup : function(element) {
var element_id = '#' + this.getInputElement().$.id;
$.ajax({
type: 'POST',
url: 'lib/ckeditor/plugins/customExam/utilities/listExams.aspx',
data: '{"cpID":' + window.parent.$("#cpID").val() + '}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: false,
success: function(data) {
$.each(data.DATA, function(index, item) {
$(element_id).get(0).options[$(element_id).get(0).options.length] = new Option(item[1], item[0]);
});
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
}
}关键是找到CKEditor设置的元素ID,它不是元素定义中的id。您可以将该id用于其他函数,但如果您计划对元素进行任何更新,则需要获取CKEditor DOM元素。
也许有一种更好的方法可以做到这一点,但这对我来说是可行的。
发布于 2011-03-14 20:54:57
鲍勃
下面是更改现有select菜单项目的代码片段。但是,您可以添加自己的值,动态获取值,等等。
//for button we just want to limit the button type to button
if ( dialogName == 'button' ) {
// updates the info tab
var infoTab = dialogDefinition.getContents( 'info' );
var typeDef = infoTab.get( 'type' );
var buttonType = new Array("Button", "button");
var myItems = new Array (buttonType);
typeDef['items'] = myItems;如果这不起作用,请提供实际结果与预期结果的更多详细信息。
发布于 2014-08-21 21:06:57
elements: [
{
type: 'select',
id: 'test',
label: 'test label',
items: [
['Please Choose', '']
],
onLoad: function(element) {
this.add('Option 1', '1');
this.add('Option 2', '2');
}
}
]如果要在对话框打开进行编辑时添加或删除项目。您可以使用setup调用。将其放置在onLoad定义的上方或下方。
setup: function(element) {
this.clear();
this.add('Please Choose', '');
this.add('Option 1', '1');
this.add('Option 2', '2');
this.setValue(element.getText());
},https://stackoverflow.com/questions/5293920
复制相似问题