JQuery .each() 메서드
http://api.jquery.com/jquery.each/
Example: Iterates through the array displaying each number as both a word and numeral
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <title>jQuery.each demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
var arr = [ "one", "two", "three", "four", "five" ];
var obj = { one: 1, two: 2, three: 3, four: 4, five: 5 };
jQuery.each( arr, function( i, val ) {
$( "#" + val ).text( "Mine is " + val + "." );
return ( val !== "three" );
jQuery.each( obj, function( i, val ) {
$( "#" + i ).append( document.createTextNode( " - " + val ) );
|
$("#listBnt").click(function viewAjax() {
$('#jsonlist').empty();
console.log("리스트 버튼 들어옴");
$.ajax({
type: "GET",
url: "/testajax/main/users/",
dataType: "json",
success: function (response) {
console.log("불러오기 성공");
// each 함수 $(불러온데이터).each(fucntion (인덱스, 불러온데이터각각의 값)){}
$(response).each(function (i,data ) {
var d = "<table class='table table-striped'>";
d += "<th class='tid'>" + data.id + "</th>";
d += "<th class='tname'>" + data.name + "</th>";
d += "<th class='temail'>" + data.email + "</th>";
d += "<th class='tage'>" + data.age + "</th>";
d += "</table>";
$("#jsonlist").append(d);
})
},
error: function (e) {
console.log("error");
console.log("error 정보 : " + e.status);
}
});
});