由于某些原因,该功能被触发两次。如果你能帮助我改进代码(是一个noobz),我将非常感激。
主要的调用功能是:
get_range_entries
一旦回调返回状态,它就会显示模态框,但不知怎的,它会转到下一行代码,因此它阻止我关闭模态窗口。
function load_XMLDoc(dname, callback) {
$.ajax({
cache: false,
type: 'GET',
dataType: "xml",
url: dname + '&date=' + new Date().getTime(),
success: function(result) {
if(typeof callback === "function") {
callback(result)
}
}
})
}
function get_range_entries(view_name, startkey, universal_id, column, callback) {
//unid = universal id
//column = column number to compare
//this is for uncategorized views only
var url;
var status = false;
url = view_name + '?ReadViewEntries&ResortAscending=' + column + '&StartKey=' + startkey + '&UntilKey=' + startkey + 'Z&ExpandView';
load_XMLDoc(url, function(result) {
viewentries = result.getElementsByTagName("viewentries");
entries = result.getElementsByTagName("viewentry");
range_entries = viewentries[0].getAttribute('rangeentries');
if (range_entries == 0) {
status = false;
}
else {
entries = result.getElementsByTagName("viewentry");
columns = entries[0].getElementsByTagName("entrydata");
if (entries[0].getAttribute('unid')) {
unid = entries[0].getAttribute('unid');
}
if (unid == universal_id)
status = false;
else {
colvalue = columns.item(column).childNodes[1].firstChild.nodeValue;
status = (colvalue.toLowerCase() == startkey.toLowerCase());
}
}
alert(1); ------------------> just using this to check if its being triggered twice
callback(status);
})
}
function display_message_string(message_title, message_string, hide_primary) {
$('#modal-confirm').find('.modal-title').html(message_title);
$('#modal-confirm').find('.modal-body').html(message_string);
if (hide_primary)
$('#modal-confirm').find('.btn-primary').hide();
else
$('#modal-confirm').find('.btn-primary').show();
$('#modal-confirm').modal('show');
}
get_range_entries(view_name, startkey, unid, 1, function(status) {
if (status) {
display_message_string("DUPLICATE ENTRIES ENCOUNTERED", "The GENERATOR NAME you are trying to save already exists in the Database ... Please try again", true);
return false; ----> added this just to prevent it from triggering twice but it doesn't seem to work
}
})
.....保存表单的下一行代码