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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -