开发者

Array length is zero in jQuery

I wrote like this. After submit click loop is not excuting. But I saw value are there, But array lenght is showing '0'. (Please see picture). Why it is not going into loop? and $('#myVisibleRows').val(idsString); becoming 'empty'.

$(document).ready(function() {

        $('tr[@class^=RegText]').hide().children('td');

        var list_Visible_Ids = [];
        var idsString, idsArray;
        alert($('#myVisibleRows').val());
        idsString = $('#myVisibleRows').val();
        idsArray = idsString.split(',');
        $.each(idsArray, function() {
            if (this != "") {
                $('#' + this).siblings(('.RegText').toggle(true));
                window['list_Visible_Ids'][this] = 1;
            }
        });
        $('tr.subCategory1')
        .css("cursor", "pointer")
        .attr("title", "Click to expand/collapse")
        .click(function() {
            //this = $(this);
            $(this).siblings('.RegText').toggle();

            list_Visible_Ids[$(this).attr('id')] = $(this).css('display') != 'none' ? 1 : null;
            alert(list_Visible_Ids[$(this).attr('id')])
        });
        $('#form1').submit(function() {

            idsString = '';
            $.each(list_Visible_Ids, function(key, val) {开发者_如何学Go
                alert(val);
                if (val) {

                    idsString += (idsString != '' ? ',' : '') + key;
                }
            });
            $('#myVisibleRows').val(idsString);                
            form.submit();
        });
    });

Array length is zero in jQuery


finally it works me like this.

 for (var index in list_Visible_Ids) {
                idsString += (idsString != '' ? ',' : '') + index;
            }


$.each is designed for enumerating the key/value pairs in OBJECTS, not arrays - as Nick Craver hinted at.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜