javascript - Dont save item to array if 'input[type='hidden']:first' is undefined -


This code gets all the data lines in my table, however, I do not want to save the item on the first object if first hidden The input ("click", function () {var array = $ .map ($ ('table tr'), function (val, I) {var obj = {}, inputs = $ (val) .find (' Td input [type = 'hidden'], input [type = 'text'], selection '); obj [inputs.filter (' input [type = 'hidden']: first '). Val ()] = $ .map (inputs.not ('input [type =' hidden ': first'], function (val, i) {return val.value;}); return obj;}); var data = JSON.stringify (array) ;});

This is a sample result of my array:

  [["add": ["orange", "1", "yes"]} [{"": [" Note the other thing, it is empty (not "add"), I do not want to save my array.   

Try this:

  var array = $ .map ($ ('Table tr'), function (val, i) {var obj = {}, inputs = $ (val). Find ('td input [type = \' hidden \ '], input [type = \' text \ '],' select '; var inputVal = inputs.filter (' input [type = \ 'hidden \']: First '). Val (); If (InputVal.length) {obj [inputVal] = $ .map (inputs.not (' input [type = \ 'hidden \']: first '), function (val, i) {Return val.value;});} return obj;}) Filter (function (val) {return! $. IsEmptyObject (val)});  

If you want to exclude the array , then you run a filter after the map Will> Call.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -