var dataArray = new Array();
$('.info_byrequests').each(function(){
var appId = $(this).attr('data-appId');
if(jQuery.inArray(appId, dataArray) == -1){
dataArray.push(appId);
}
});
get_applications().done(function(value) {
var html_string = value;
// sort and compare results with actual HTML
$('#list_app').html(html_string);
});
echo "<div data-appId=\"" . $result[ 'application_id' ] . "\" class=\"form_title info_byrequests date\">" . str_replace( " ", "-", $result[ 'app_date' ] ) . "</div>";
for(var i=0; i<=dataArray.length; i++){
// console.log('ID: ' + dataArray[i]);
}
I need to search for every instance of data-appIdThis is straight forward - find all <div> that has a custom data attribute appId
Number compared by in javascript arrayNot sure what you mean here
remove the intire div before displaying html to screenWhich entire div? Based on what criteria.
var html = '<div data-appId="123" class="form_title info_byrequests date">20200101</div><div></div><div></div>';
var jq = $(html);
jq.each(function(index, value) {
if (value.dataset.appid) {
// this element has a data-appId value
}
})
echo "<div data-appId=\"" . $result[ 'application_id' ] . "\" class=\"form_title info_byrequests date\">" . str_replace( " ", "-", $result[ 'app_date' ] ) . "</div>" . chr(13);
echo "<div data-appId=\"" . $result[ 'application_id' ] . "\" class=\"form_title info_byrequests appNumber\">" . str_replace( " ", "", $result[ 'app_date' ] ) . "-" . $result[ 'application_id' ] . "</div>";
echo "<div data-appId=\"" . $result[ 'application_id' ] . "\" class=\"form_title info_byrequests name\">" . strtoupper($result[ 'last_name' ] . ", " . $result[ 'first_name' ]) . "</div>";
echo "<div data-appId=\"" . $result[ 'application_id' ] . "\" class=\"form_title info_byrequests phone\"><span class=\"telephone\">" . $result[ 'telephone' ] . "</span></div>";
echo "<div data-appId=\"" . $result[ 'application_id' ] . "\" class=\"form_title info_byrequests creditType\">" . $result[ 'credit_type' ] . "</div>";
echo "<div data-appId=\"" . $result[ 'application_id' ] . "\" class=\"form_title info_byrequests creditAmount\"><span class=\"dollar_sign\">$</span><span class=\"requested_credit\">" . $result[ 'credit_amount' ] . "</span></div>";
echo "<div data-appId=\"" . $result[ 'application_id' ] . "\" class=\"form_title info_byrequests status\"><i class=\"" . $result[ 'class' ] . "\" title=\"" . $result[ 'status_name' ] . "\"></i></div>";
echo "<div class=\"clear_all\"></div>";
lets say I have a javascript array as followsvar dataArray = new Array("55", "56", "57");
As you can see there are many div's with data-appId that will have the same value. the data value is compared with data already displayed to screen. to avoid duplicates, I want to remove all the div's that have data-appId=55 & 56 & 57 (as seen in the array) before I append the html string to the current html
As you can see there are many div's with data-appId that will have the same value.I can't see - there is no data that shows this.
// determine what data we already have
var dataArray = new Array();
$('.info_byrequests').each(function(){
var appId = $(this).attr('data-appId');
if(jQuery.inArray(appId, dataArray) == -1){
dataArray.push(appId);
}
});
setInterval(function() {
populate_applications();
// console.log('Update');
}, 5000);
nor have you explained what must happen.
for instance - if the data received from the AJAX call contains the appId's 10,11,12,13 and you already have 10 and 11 showing - you only want to show 12 and 13? So we check each incoming appId against the array - if we find one that does not match - we then add that to the screen - AND then update the array with this id?
When you land on the page at first, it will display all the proper resultsHow do the id's from those results get into the array?
Open in new window
In your case it is not clear what you want to do with the string - if you could explain a bit more I can better advise you.The above code demonstrates how to use an HTML string in the same way you would an HTML document using jQuery.