all,
I have an array that does not seem to get populated. I can see that the length of my array but can't seem to view the data with a simple alert.
My function is called when I click on an href:
I then look for elements that have a class of .jobRole to populate my array and to be displayed with alert. However I'm having difficulties. Thanks for any assistance.
function close() {
var jobRoleArray = [];
$(".jobRole").each(function (index) {
var jobRoleIndex = index;
var jobRoleID = $(this).attr('id');
var jobRoleName = $(this).text();
var roleInfo = {
"roleIndex": jobRoleIndex,
"roleID": jobRoleID,
"roleName": jobRoleName
};
queryStr = { "roleInfo": roleInfo };
jobRoleArray.push(queryStr);
});
alert('show length: ' + jobRoleArray.length);
for (var i = 0; i < jobRoleArray.length; i++) {
alert('jobRoleIndex: ' + jobRoleArray[i].roleInfo.jobRoleIndex +
' jobRoleID: ' + jobRoleArray[i].roleInfo.jobRoleID +
' jobRoleName: ' + jobRoleArray[i].roleInfo.jobRoleName +
' showCount: ' + i);
}
}
mapfunction, which lets you transform jQuery objects into arrays:var jobRoleArray = $(".jobRole").map(function(jobRole, index) { var jobRoleIndex = index; var jobRoleID = jobRole.attr("id"); ... return queryStr; });