-2
在开始之前,我已经花了很长时间阅读本: How do I return the response from an asynchronous call?从异步调用返回响应
我有一个硬编码变量,被称为“d”,被定义为一个二维数组:
var d = [
["05_001","05_002","05_003","05_004","05_005"],
["05_006","05_007","05_008","05_009","05_010"]
];
我想使用AJAX get,所以我可以从数据库中获取值。
我想这个简单的解决方法:
function foo(callback) {
return $.ajax({
url: 'emoji.php?cat=emoticons_activity',
success: callback
});
}
var result;
foo(function(response) {
result = response;
alert(result);
});
但是,即使我这样做,我仍然停留,因为我还需要设置变量“d”的值是通过返回的值“富“功能。
我需要使用代码这段代码的情况下:
tinymce.PluginManager.add("emoticons_travel_places", function(a, b) {
function c() {
var a;
return a = '<table role="list" class="mce-grid">', tinymce.each(d, function(c) {
a += "<tr>", tinymce.each(c, function(c) {
var d = b + "/img/" + c + ".svg";
a += '<td><a href="#" data-mce-url="' + d + '" data-mce-alt="' + c + '" tabindex="-1" role="option" aria-label="' + c + '"><img src="' + d + '" style="width:30px; height:30px" role="presentation" /></a></td>'
}), a += "</tr>"
}), a += "</table>"
}
var d = [
["05_001","05_002","05_003","05_004","05_005","05_006","05_007","05_008","05_009","05_010","05_011","05_012","05_013","05_014","05_015","05_016","05_017","05_018","05_019","05_020"],
["05_021","05_022","05_023","05_024","05_025","05_026","05_027","05_028","05_029","05_030","05_031","05_032","05_033","05_034","05_035","05_036","05_037","05_038","05_039","05_040"],
["05_041","05_042","05_043","05_044","05_045","05_046","05_047","05_048","05_049","05_050","05_051","05_052","05_053","05_054","05_055","05_056","05_057","05_058","05_059","05_060"],
["05_061","05_062","05_063","05_064","05_065","05_066","05_067","05_068","05_069","05_070","05_071","05_072","05_073","05_074","05_075","05_076","05_077","05_078","05_079","05_080"],
["05_081","05_082","05_083","05_084","05_085","05_086","05_087","05_088","05_089","05_090","05_091","05_092","05_093","05_094","05_095","05_096","05_097","05_098","05_099","05_100"],
["05_101","05_102","05_103","05_104","05_105","05_106","05_107","05_108","05_109","05_110","05_111","05_112","05_113","05_114","05_115"]
];
a.addButton("emoticons_travel_places", {
type: "panelbutton",
panel: {
role: "application",
autohide: !0,
html: c,
onclick: function(b) {
var c = a.dom.getParent(b.target, "a");
c && (a.insertContent('<img src="' + c.getAttribute("data-mce-url") + '" width="30" height="30" alt="' + c.getAttribute("data-mce-alt") + '" />'), this.hide())
}
},
tooltip: "Emoticons - Travel & Places"
})
});
凡var d = ...
位被什么是AJAX调用返回所取代。
我不能重写整个代码,因为它被TinyMCE插件系统使用。
我觉得我很亲密,但一直在卡住,并且一直在关闭和关闭几天。
没有@idiot即可资讯从异步代码返回。你必须或者让请求同步(在UI线程中被删除)或者在成功回调中运行你的'a.addButton'代码。 –