yii extensions - How to implement a dynamic js script in Yii List View? -


hello , reading question. have typical list view:

 <?php $this->widget('bootstrap.widgets.tblistview',array(     'dataprovider'=>$dataprovider,     'itemview'=>'_view',         'emptytext'=>'no jobs',              )); ?> 

in _view file have div , button slidetoggles div. if put javascript @ top of page, not work because results dynamic , name of div changes id returned, eg:

id="detailsdiv-<?php echo $data->id_employer_contract;?>" 

the problem in javascript, follows:

<?php yii::app()->clientscript->registerscript('details', "$('#details-$data-id_employer_contract').click(function(){ $('#detailsdiv-$data->id_employer_contract').slidetoggle(); return false;});");?> 

how can make javascript code dynamic? meaning, how can loop through id? tried adding code listview property ajaxupdate it's still not working. can tell me how can loop javascript in list view?

add id toggle buttons data attribute:

<button class="toggledetails" data-id="<?php echo $data->id_employer_contract ?>"> 

then can access these data attributes js:

<?php yii::app()->clientscript->registerscript('toggledetails', "     $('.toggledetails').click(function(e){         var id = $(this).data('id');         $('#detailsdiv-' + id).slidetoggle();         e.preventdefault();     }); ", cclientscript::pos_ready) ?> 

note: should not put javascript _view.php main file render list view. need 1 single snippet deal buttons.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -