jquery 中的数组未填充
所有,
我有一个似乎没有填充的数组。我可以看到数组的长度,但似乎无法通过简单的警报查看数据。
当我单击 href 时,将调用我的函数:
然后,我查找具有 .jobRole 类的元素来填充我的数组并显示警报。但是我遇到了困难。感谢您的任何帮助。
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);
}
}
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有访问正确的属性;使用这个代替:
You aren't accessing the correct properties; use this instead: