Updating CListView maintaining event handlers
I am using Yii framework, and make an extensive use of CListViews. However i am continously facing a problem which i cant开发者_高级运维 solve:
This is my CListView
$this->widget('zii.widgets.CListView', array(
'viewData'=>array('sent'=>$sent),
'dataProvider'=>$dp,
'pager' => array(
'prevPageLabel'=>'< Prev.',
'nextPageLabel'=>'Next>',
'header'=>'Pagina: ',
'pageSize'=>5,),
'template'=>"{items}\n{pager}",
'itemView'=>'_messageView',
'emptyText'=>'Empty inbox',
'enablePagination'=>true,
'afterAjaxUpdate' => 'js:function(id) {alert("after");}',
'id'=>'listMessages',
));
And i have a JS method which updates the list the following way:
function sent_view(){
$.fn.yiiListView.update('listMessages',
{data:'type=sent', url:'view?sort=timestamp&ajax=listMessages'});
}
After this function is called, all events that were tied up to each item of the CListView is no longer there. I tried adding the next piece of code so as to attach the handlers again, however it doesn't work. It doesn't even get to display an alert if i add it right after the $.fn.yiiListView.update line of code.
$(".individualMessage").mouseover(function(){
$(this).css('cursor','pointer');
$(this).css("background",'url(/../images/messages/background.png)');
});
Has someone encountered a similar problem? thank you!
You need to use jQuery's "live" function e.g.
$(".individualMessage").live("mouseover",function(){
$(this).css('cursor','pointer');
$(this).css("background",'url(/../images/messages/background.png)');
});
精彩评论