gpt4 book ai didi

javascript - CKeditor 使用 Ajax 填充对话框选择

转载 作者:行者123 更新时间:2023-11-30 05:34:44 24 4
gpt4 key购买 nike

我正在尝试使用 ajax 填充我的 CKeditor 对话框选择框。以下内容来 self 的 plugin.js 文件:

...
{
type : 'select',
id : 'style',
label : 'Style',
setup : CKEDITOR.ajax.post( '.../ckeditor/plugins/simpleLink/ajax.php', JSON.stringify( { foo: 'bar' } ), 'application/json', function( data ) {
console.log( data);
}),
items : [ ['--- Select something ---', 0] ],
commit : function( data )
{
data.style = this.getValue();
}
}
...

ajax 输出如下所示:

["Basketball","basketball"],["Baseball","baseball"],["Hockey","hockey"]

我真的很想知道如何将输出放入“项目”。从我的 Angular 来看,我尝试了一切。有人可以帮助我吗?

最佳答案

CKEditor 选择小部件有一个“添加”功能,您可以调用它来填充它们。如果添加一个,您可以从“onLoad”函数中调用它:

{
type: 'select',
id: 'myselect',
label: 'The select will be empty until it is populated',
items: [ ],
onLoad: function(api) {
widget = this;
$.ajax({
type: 'GET',
url: 'path/to/your/json',
dataType: 'json',
success: function(data, textStatus, jqXHR) {
for (var i = 0; i < data.length; i++) {
widget.add(data[i]['label'], data[i]['value']);
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('ajax error ' + textStatus + ' ' + errorThrown);
},
});
},
},

关于javascript - CKeditor 使用 Ajax 填充对话框选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24633504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com