モーダルダイアログを表示する関数を作成しようとしています。ダイアログが閉じられるまでブロックを呼び出すと、呼び出し元に返すjQuery/UIのダイアログでダイアログ( "オープン")コールをブロックするには
次の機能は2つの問題があります。
- ダイアログが開いている間に結果を返します。
- セレクタテストでダイアログが見つからない場合、ダイアログボックスの作成後に、
id
要素が失われていることがFirebugで検査されます。
。
function getCountrySelection() {
var ctryCode;
var dlg = $("#JS-field-dlg-ctry-select");
if (dlg.size() === 0) {
dlg = $("<div id='JS-field-dlg-ctry-select' title='Select Country' class='dialog-fields'></div>");
dlg.append("Customer found in both Australia and New Zealand");
dlg.dialog({
autoOpen: false,
width: 400,
height: 160,
modal: true,
buttons: {
"Australia": function() {
ctryCode = "au";
$(this).dialog("close");
},
"New Zealand": function() {
ctryCode = "nz";
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
}
dlg.dialog('open');
return ctryCode;
}
EDIT:私は私がこれを呼んでいる方法を示したいと思った:
buttons: {
"Find": function() {
var custAu = JS.sales.getCustomer("au", inpCust.val());
var custNz = JS.sales.getCustomer("nz", inpCust.val());
var cust;
if (custAu === undefined && custNz === undefined) {
alert('No customer could be found with that number.');
return;
} else if (custAu !== undefined && custNz !== undefined) {
var ctry;
getCountrySelection(function(result) {
ct = result;
});
if (ctry === "au") {
cust = custAu;
} else if (ctry === "nz") {
cust = custNz;
} else {
return;
}
} else if (custNz === undefined) {
cust = custAu;
} else {
cust = custNz;
}
if (cust) {
$(this).dialog("close");
// Do something with cust.
} else {
alert('Customer could not be found.');
}
},
"Cancel": function() {
$(this).dialog("close");
}
}
。 – Pointy