jquery - Foreach loop javascript failing -
why each statement cause code break? have set index javascript?
var email = []; email['update'] = true; email['e_case_id'] = $("#e_case").val(); var = 0; $.each($('.rowchecked'), function() { email['e_attachments'][i] = $(this).attr('id'); i++; });
firstly, email
should object literal, not array literal:
var email = {};
secondly, didn't define email['e_attachments']
before tried use it. what's prevent working. try adding
email['e_attachments'] = [];
before $.each
.
you can use $.map
in circumstance, btw. is:
email['e_attachments'] = $.map($('.rowchecked'), function (el) { return $(el).attr('id'); });
instead of $.each
. or better yet:
email['e_attachments'] = $('.rowchecked').map(function () { return $(this).attr('id'); }
Comments
Post a Comment