댓글의 요약을 보여주고 버튼을 누르면 해당 내용을 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('실패');
})
});
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('실패');
})
});
댓글 4
배열 순서는 무시하고, comment_srl을 기준으로 필터링해 보세요.
주어진 배열값에서 comment_srl을 기준으로 필터링하는 게 제 실력으로는 어려워서 그쪽으로는 접근하지 못했습니다^^; 대신 proto님 말씀 듣고 comment_srl을 파라미터로 받으니 index 값이 제대로 잡히네요. 기진곰님도 도움을 주셔서 감사합니다.
for ( var i = 0, c = data.comment_list.length; i < c; i++; ) {
if( data.comment_list[i].comment_srl == 파라미터 ) {
~~
}
}