댓글의 요약을 보여주고 버튼을 누르면 해당 내용을 exec_json으로 불러오는 방식을 적용하고자 했습니다. 기존에 제공하는 dispBoardContentCommentList 함수를 이용해서 불러오고자 했는데, 이게 원하는 댓글 하나의 정보만 가져오는 게 아니라 리스트(배열)를 가져오는 것이다 보니 댓글의 index가 필요하더라구요. 순서만 지켜지면 되니까 그냥 index()로 하면 되겠지 싶었는데 제 부족한 지식으로는 해당 댓글의 index를 제대로 받아오지 못해서... 어떤 식으로 작성하면 구할 수 있을까요? 아래와 같이 작성해서 시도해 보았습니다.
jQuery('.more').on('click', function() { var $this = jQuery(this); var idx = $('a.more').index(this); //위치... var document_srl = $this.attr('data-document_srl'); $this.html('Loading...'); exec_json( 'board.dispBoardContentCommentList', {document_srl: document_srl}, function(data) { var list = data.comment_list; $this.after(list[idx].content); }, function(data) { $this.html('실패'); }) });
배열 순서는 무시하고, comment_srl을 기준으로 필터링해 보세요.