jQuery .each 通过 POST 嵌套数组
我有一个看起来像这样的 POST:
Array
(
[students] => Array
(
[37] => Array
(
[name] => 37
[registration_payment_date] =>
[check_amount] => 120.00
)
[38] => Array
(
[name] => 38
[registration_payment_date] => 9-11-2011
[check_amount] => 117.00
)
)
)
我想循环遍历 .submit 函数中内部数组的键和值,以验证是否有支票金额,然后应该有付款日期。如果没有付款日期,那么我会将该名称添加到数组中,然后提醒该名称列表。 我在使用 jQuery.each 函数时遇到问题。我假设应该有一个外部 .each 和一个内部 .each。我有 var form = this 那么 -
var names = "";
jQuery(form.students).each(function(){
//ANOTHER EACH HERE?? {
//AN IF STATEMENT HERE {
names.push( students['name'];
}
})
});
alert(names);
我想我已经很接近了,但还没有完全实现。任何人都可以填写空白(或告诉我我偏离轨道)吗?
I have a POST that looks something like this:
Array
(
[students] => Array
(
[37] => Array
(
[name] => 37
[registration_payment_date] =>
[check_amount] => 120.00
)
[38] => Array
(
[name] => 38
[registration_payment_date] => 9-11-2011
[check_amount] => 117.00
)
)
)
I want to loop through the key and value of the inner array in the .submit function to verify that if there is a check amount then there should be a payment date. If no payment date then I will add that name to an array then alert that list of names.
I'm having trouble with the jQuery.each function. I'm assuming there should be an outer .each and an inner .each. I have var form = this then-
var names = "";
jQuery(form.students).each(function(){
//ANOTHER EACH HERE?? {
//AN IF STATEMENT HERE {
names.push( students['name'];
}
})
});
alert(names);
I'm close, I think, but not quite there. Can anyone fill in the blanks (or tell me I'm off track) please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你几乎已经拥有它了,当你每次使用 jQuery 时,它都会为你提供你正在循环的当前项目的索引。在这种情况下我们使用
i
。You pretty much have it, when you use jQuery each, it gives you an index of the current item you are looping over. we use
i
in this case.我删除了 if 因为我无法清楚地得到你想要的东西,所以你可以相应地定位自己。
这就是你要找的吗?
I removed if because i cant get what u want clearly so u can put yourself accordingly.
Is this what ur looking for.