现状:
我正在使用wenzhixin JQuery Multiple-Select-Plugin提供一个multiselect下拉框(请参见http://multiple-select.wenzhixin.net.cn/home/)。我在页面上有该Multiselect-Dropdownbox的两个实例(我在JSFiddle中使它类似,但是似乎可以正常工作...)。
问题:
在两个AJAX调用的.done()-Method中,我无法获取onClick-Listener。在下面的示例中,click()-Event
$('#cbTailoringCategory').multipleSelect( { onClick: function() {...} })
不起作用,但是它将选择字段变为多选下拉列表。 但是,当我这样编写change()-Listener时,它就起作用了(但这会触发两次):
$('#cbRoles').change(function (event) {
refreshDiagramNodes();
}).multipleSelect({
});
问题
我该如何使用不必使用change()-Method的click()-Event来工作?
JsFiddle
我试图在JsFiddle中隔离问题,但是它在这里:-/
https://jsfiddle.net/schludi/6z0ns475/
在...完成... jquery时,我的代码全面结合了AJAX调用:
我的代码的原始AJAX调用如下:
var myTailoringCategories = {};
var myKeypointResponsibles = {};
function loadTailoringCategories() {
$.when(
$.ajax({
type: "POST",
url: '/Services/DiagramService.asmx/GetTailoringCategories',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var pcpTailoringCategories = msg.d;
$.each(pcpTailoringCategories, function (index, pcpTailoringCategory) {
myTailoringCategories[pcpTailoringCategory.tailoringcategory] = pcpTailoringCategory.tailoringelements;
$('#cbTailoringGroups').append($('<option>', {
value: pcpTailoringCategory.tailoringelements,
text: pcpTailoringCategory.tailoringcategory
}));
});
},
error: function (e) {
console.log('FEHLER! ' + e.responseText);
}
}),
$.ajax({
type: "POST",
url: '/Services/DiagramService.asmx/GetKeypointResponsibles',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var keypointResponsibles = msg.d;
$.each(keypointResponsibles, function (index, keypointResponsible) {
myKeypointResponsibles[keypointResponsible] = keypointResponsible;
$('#cbRoles').append($('<option>', {
value: keypointResponsible,
text: keypointResponsible
}));
});
},
error: function (e) {
console.log('FEHLER! ' + e.responseText);
}
})
).done(function (result1, result2) {
updateCBFilter();
// Hier wird aus der Multiselect-Box eine Rollen-Liste
$('#cbRoles').change(function (event) {
refreshDiagramNodes();
}).multipleSelect({
});
// Hier wird aus der Multiselect-Box eine Tailoring-Liste
$('#cbTailoringGroups').multipleSelect({
onClick: function () {
alert('Click Event');
}
});
$('#cbTailoringGroups').multipleSelect('refresh');
//initializeTailoringCategories();
loadAllDiagramNodes(diagramType);
});
}
答案 0 :(得分:0)
我发现,该功能
refreshDiagramNodes();
产生了一个错误,因此Javascript引擎较早退出/终止-以此顺序,脚本onClick()-Event没有被触发。