jQuery .each 通过 POST 嵌套数组

发布于 2024-12-05 05:09:22 字数 907 浏览 0 评论 0原文

我有一个看起来像这样的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自演自醉 2024-12-12 05:09:22

你几乎已经拥有它了,当你每次使用 jQuery 时,它都会为你提供你正在循环的当前项目的索引。在这种情况下我们使用i

var names = "";
$(form.students).each(function(i,el){
    $(form.students[i].each, function() {
        //AN IF STATEMENT HERE {
            names.push( students[i]['name'];
        }
    })
});
alert(names);

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.

var names = "";
$(form.students).each(function(i,el){
    $(form.students[i].each, function() {
        //AN IF STATEMENT HERE {
            names.push( students[i]['name'];
        }
    })
});
alert(names);
花桑 2024-12-12 05:09:22
var names=new Array();
$.each('form.students',function(){
    $.each(this,function() {
            names.push(this.name);
        });
    });
alert(names);

我删除了 if 因为我无法清楚地得到你想要的东西,所以你可以相应地定位自己。
这就是你要找的吗?

var names=new Array();
$.each('form.students',function(){
    $.each(this,function() {
            names.push(this.name);
        });
    });
alert(names);

I removed if because i cant get what u want clearly so u can put yourself accordingly.
Is this what ur looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文