Ich habe ein Problem in einer Schleife in JQUERY. Ich erhalte dank einer "Get" -Abfrage einige Daten (im JSON-Format).
Ich möchte diese Daten in eine Dropdown-Liste mit "optgroup" einfügen. Aber ich habe Probleme, die optgroup zu machen.
Ich möchte den vorherigen Wert mit dem aktuellen Wert in der $ .each Schleife vergleichen, bevor die optgroup Einfügen:
=> IF aktueller_wert (v.SG_CODE) = previous_value (v.SG_CODE) DANN add optgroup
Aber ich weiß nicht, wie man es bekommt. Kannst du mir bitte Helfen ?
Ich habe diesen Code:
function myFunction (param){
var select = $("#myselect");
select.empty();
select.append(
new Option('Loading...', '-1')
);
var jqXHR = $.getJSON("myCFC.cfc", {
"method" : "myMethod",
"param": param,
});
setTimeout(function(){
// If status in pending, call the method fail
if (jqXHR && jqXHR.state() === "pending"){
jqXHR.abort();
}
}, 3000); // 3s
jqXHR.done(function(data, textStatus, jqXHR){
// success - Treatment of the request
//console.log(data, textStatus, jqXHR);
select.empty();
console.log(data.length);
if(data.length>0){
select.show();
$.each(data,function(k,v){
//alert(v.ID + " --- " + v.VALUE);
select.append('<optgroup label="' + v.SG_CODE +'">');
select.append('<option value="' + v.ID + '">' + v.SUBJECT_CODE + '</option>');
select.append('</optgroup>');
});
}else{
select.hide();
}
});
jqXHR.fail(function(jqXHR, textStatus, errorThrown){
// AJAX Request failed
console.log(jqXHR, textStatus, errorThrown);
});
jqXHR.always(function(jqXHR, textStatus){
//console.log(jqXHR, textStatus);
})
}
Vielen Dank im Voraus für Ihre Hilfe.
Grüße,
Seb
speichern, wo genau Sie den Geburtstag Vergleich wollen? –
Ich möchte v.SG_CODE [currentrow] mit v.SG_CODE [currentrow-1] vergleichen, bevor ich die optgroup: select.append ('