JQuery UI上下文菜单AJAX加载
我得到了如下定义的contextMenu操作:JQuery UI上下文菜单AJAX加载,jquery,ajax,jquery-ui,contextmenu,Jquery,Ajax,Jquery Ui,Contextmenu,我得到了如下定义的contextMenu操作: $("#conteneurMenuNotifications").contextmenu({ delegate: ".hasMenuNotifications", autoFocus: true, preventContextMenuForPopup: false, preventSelect: true, taphold: true, autoTrigger: false, beforeO
$("#conteneurMenuNotifications").contextmenu({
delegate: ".hasMenuNotifications",
autoFocus: true,
preventContextMenuForPopup: false,
preventSelect: true,
taphold: true,
autoTrigger: false,
beforeOpen: function(event, ui){
var request = $.ajax({type: "GET",
url: "/getData/var1/var2",
cache: false
});
request.done(function(msg){
$("#conteneurMenuNotifications").contextmenu("replaceMenu",
[{title: "---"},
{title: "<b>Notifications</b>", disabled: true}]);
for(var i = 0; i < msg.length; i ++){
var notif = msg[i];
$("#conteneurMenuNotifications").contextmenu("setEntry",
[{title: notif.label + "-" + notif.title}]);
}
});
request.fail(function(jqXHR, textStatus, errorThrown) {
if (jqXHR.status == "500") {
window.location.href = "/foagan/resources/html/indispo.html";
} else {
$("#dialogueTache").html(jqXHR.status + " - " + jqXHR.responseText);
$("#dialogueTache").dialog("option", "title", "Erreur");
$("#dialogueTache").dialog("open");
}
});
}
});
它是用法语写的。。。英文应为:
'this.$menu' as Null value or is not an object.
有什么想法吗
编辑
我已将代码更改为使用替换菜单:
request.done(function(msg){
var tab = [];
tab.push({title: "<b>Notifications</b>", disabled: true}, "---");
for(var i = 0; i < msg.length; i ++){
var notif = msg[i];
tab.push({title: label + '-' + title});
}
tab.push({title: "---");
tab.push({title: "Afficher tout", action: function(event, ui) { debrancherVersAfficherTousEvenements(); });
$("#conteneurMenuNotifications").contextmenu("replaceMenu", tab);
//dfd.resolve();
$("#conteneurMenuNotifications").contextmenu("open", $(".hasMenuNotifications:first"));
});
request.done(函数(msg){
var选项卡=[];
tab.push({title:“通知”,disabled:true},“--”);
对于(变量i=0;i
但是现在我在这个beforeOpen函数上有一个无限循环!你能创建一个fiddle/MCVE吗?我在上面的代码中看到的唯一错误是(根据自述文件)您使用的
setEntry
错误:它需要两个参数,但只得到一个是的,这是第一个错误,谢谢!我已将代码更改为使用replaceMenu,因为我还有其他问题。问题已编辑!ajax调用中的contextMenu(“open”)
似乎生成了这个无限循环。
request.done(function(msg){
var tab = [];
tab.push({title: "<b>Notifications</b>", disabled: true}, "---");
for(var i = 0; i < msg.length; i ++){
var notif = msg[i];
tab.push({title: label + '-' + title});
}
tab.push({title: "---");
tab.push({title: "Afficher tout", action: function(event, ui) { debrancherVersAfficherTousEvenements(); });
$("#conteneurMenuNotifications").contextmenu("replaceMenu", tab);
//dfd.resolve();
$("#conteneurMenuNotifications").contextmenu("open", $(".hasMenuNotifications:first"));
});