I have an instance of clistview which contains multiple instances of clistview in small views. I need to refresh individual clistview everytime an action is performed. The problem is, whenever I switch from one clistview to the other to perform a certain action, delete for example, it sends request or loads the function n number of times, n being the number of reloads the clistview have gone through with update function. Can anybody point me out where the problem is? I found this which came very close but didn’t solve my problem. My code is as follows: javascript for child clistview update:
function commentPoster()
{
$('div.update-meta').on('click','a.del', function()
{
var commentID = $(this).parent().attr('rel');
var commentsContainer = $(this).parent().parent().parent().parent().parent().parent().attr('id');
/**
* send ajax request to load comment content
*/
$.ajax({
url:'<?php echo Yii::app()->createUrl('comments/deleteComment');?>',
data:{cID:commentID},
type:'POST',
success:function(returnData)
{
if(returnData *1 == 1)
{
$.fn.yiiListView.update(commentsContainer);
}
},
beforeSend:function(xhr)
{
}
});
});
}
commentPoster();
and this is how this function is called in clistview:
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$comments,
'afterAjaxUpdate'=>'js:function(id, data){commentPoster();}',
'ajaxType'=>'GET',
'itemView'=>'_comments',
'id'=>'comments_'.$postDetail['id'].'_'.($index+1).'-list',
'emptyText'=>'',
'template'=>'{items}{pager}',
'itemsTagName'=>'ul',
'itemsCssClass'=>'comments pre-msg'
)
);
Is it because of the behavior of clistview or I have done something wrong? Can anybody please help me?