我想用Ajax查询中的数据填充select元素。我正在接收数据:CKEditor 4:在插件对话框中添加动态选择元素
['而这里'对此书签发表评论。 ...,250'],['哇, 另一个评论。 ...,251'],['好吧,它'是另一个评论。 ...,252']
...但我不能用数据填充实际的select元素。到目前为止,我有:
CKEDITOR.dialog.add('commentDialog', function(editor) {
function get_bookmark_comments_as_object() {
var objBookmark = new Object({
items: []
});
objBookmark.id = 7193;
$.ajax({
url: base_url + "comments/jq_get_bookmark_comments_as_object/" + objBookmark.id,
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
async: false,
success: function (element) {
for (var i=0;i<element.length;i++) {
objBookmark.items.push("['" + element[i].comment_snippet + ", " + element[i].bookmark_comment_id + "']");
}
String.prototype.unquoted = function() { return this.replace (/(^")|("$)/g, '') }
var string = objBookmark.items.join(', ');
console.log(string);
return string.unquoted();
},
error: function() {
}
});
}
...
...和:
return {
// Basic properties of the dialog window: title, minimum size.
title: 'Comment Properties',
minWidth: 400,
minHeight: 200,
// Dialog window contents definition.
contents: [
{
// Definition of the Basic Settings dialog tab (page).
id: 'tab-basic',
label: 'Basic Settings',
// The tab contents.
elements: [
{
// Text input field for the abbreviation text.
type: 'select',
id: 'comment',
label: 'Select a Comment',
items: [['Select a Comment', 0]].concat(get_bookmark_comments_as_object()),
setup: function(element) {
this.setValue(element.getText());
},
commit: function(element) {
...
}
}
]
}
],
你可以从get_bookmark_comments_as_object()
功能看到的,我回国的确切格式的字符串。
任何尝试返回普通数组或字符串都会使select元素表现怪异(例如,围绕字符串的双引号导致CKEditor将整个字符串拆分为字符部分)。然而,当我从console.log()
结果中复制并粘贴时,它就可以工作。
我已经尝试了许多变化items: ...
没有可用的结果。
我试着将jQuery/Ajax代码放在setup: ...
和commit: ...
中,但没有可用的结果。
我也试过fix from a similar thread,但那也没有做任何事情。
我已经走得尽可能多了,对我来说还是一个谜。
更新
经过一番扑各地,我发现:
var items = [['And here's a comment on this Bookmark. ...', '250'], ['Wow, another comment. ...', '251'], ['Okay, it's just another comment. ...', '252']];
...作品,而:
var items = get_bookmark_comments_as_object();
...不,即使这些字符串是相同的。因此,无论出于什么原因,CKEditor(或者我认为,JavaScript)都在窒息,我不知道该怎么做。
这不是为我工作,我得到了以下错误'selectList.add不是function'因为“这”是不能工作的对话框或者我失去了在你的答案东西... – Drakkin
我已经进入CKEDITOR的细节已经有一段时间了。对不起,我不确定你的情况。 = / – rarrarrarrr