samedi 23 avril 2016

Joining 2 result

I have a button that does the following to rows that are checked. I added .join('') to remove a comma that will appear from 2nd return value onwards

var getName = $("input:checkbox:checked").map(function() {
return ($(this).parent().next().next().next().next().next().next().text());
}).get().join('');

var getNum = $("input:checkbox:checked").map(function() {
return ($(this).parent().next().next().next().next().text());
}).get()join('');

alert(getName.concat(getNum));   

The output is as follows when i checked 3 rows and clicked the button:

Name1
Name2
Name3
Num1

Num2

Num3


When i stringify the return elements:

var getName = $("input:checkbox:checked").map(function() {
return JSON.stringify($(this).parent().next().next().next().next().next().next().text());
}).get().join('');

var getNum = $("input:checkbox:checked").map(function() {
return JSON.stringify($(this).parent().next().next().next().next().text());
}).get()join('');

alert(getName.concat(getNum));    

The output is as follows:

"\n Name1""\n Name2""\n Name3""\n Num1\n ""\n Num2\n ""\n Num3\n "


How can i get the output to be like this?

Name1 Num 1
Name3 Num 2
Name3 Num 3




Aucun commentaire:

Enregistrer un commentaire