碰到奇怪的问题???

用’CGridView’显示数据,有一列为’CCheckBox’,发现一个奇怪的问题,在 CGridView 显示很多数据,存在分页。查看第一页源码和第二页源码,发现源码当中显示的数据都是一样的??? :unsure: 包括ID,value等,查看其它页面的源码也是一样的,都是和第一页源码数据相同!不知道是为什么,查看了’CCheckBox’的API,有这么一句话:


By default, the checkboxes rendered in data cells will have the values that are the same as the key values of the data model. 

One may change this by setting either name  or value.

,我想应该设置 ‘name’ 和 'value’属性就可以显示不唯一的数据,但是设置之后,所有页面的源码数据还是一样的,所有页面和第一页源码数据相同!不知道为什么??? :unsure: 按理说应该是第一页显示:1-10数据,第二页显示:10-20数据,源码内容当中的数据应该是这样才对!

由于我现在用jquery来获取每条数据当中’checkbox’的ID,在第一页可以得到每条数据的ID,但是当我翻页到第二页时,就没有反应了,不能得到 'checkbox’的ID,而且我又到跳转到第一页发现第一页当中的’checkbox’的ID也获取不到了,Jquery不起作用了?要重新刷新页面才能得到第一页的ID,我想可能是在这个地方出了问题:每页的源码数据都是一样的!怎么改才能让每页源码显示的数据内容不一样呢???help me! thanks…

JS:




<script type="text/javascript">

   $(document).ready(function(){

		$("[name='yw1_c1[]']").click(function(){

            alert(this.value);

            var value = this.value;

            var a = 1;

            var check = this.checked;

            if(check == true){

                a = 1;

            }else{

                a = 0;

            }

			$.ajax({

                async:false,

                url:'http://localhost/email/index.php?r=email/getsetting',

				type:'GET',

				data:'value='+value+'&a='+a,

				dataType:'text',

				timeout:1000,

				error:function(){

					alert('Error!');

				},

//                success:function(){

//                    alert('success!');

//                }

			});

		});

	});




View:




<?php $this->widget('zii.widgets.grid.CGridView', array(

			'dataProvider'=>$setting->search(),			

			'summaryText'=>Yii::t('email','结果:{start}-{end} of {count}'),

			'selectableRows'=>0,			

			//'filter'=>$search,				

			'columns'=>array(

				array(

					'name'=>'emailaccount_name',

					'value'=>'$data->emailaccount_name',

					'headerHtmlOptions'=>array('width'=>'20px'),

				),				

				array(

					'class'=>'CCheckBoxColumn',	

					'header'=>Yii::t('email','email_from'),

					'value'=>'$data->emailaccount_name',					

					'headerHtmlOptions'=>array('width'=>'50px'), 

				),			

				array(

					'class'=>'CCheckBoxColumn',	

					'header'=>Yii::t('email','email_to'),

					'value'=>'$data->emailaccount_name',

					'headerHtmlOptions'=>array('width'=>'50px'),

				),			

			),

          'pager'=>array(

                'class'=>'CLinkPager',

                'firstPageLabel'=>Yii::t('email','首页'),

                'lastPageLabel'=>Yii::t('email','末页'),

                'nextPageLabel'=>Yii::t('email','下一页'),

                'prevPageLabel'=>Yii::t('email','上一页'),

            )

)); ?>	




或许是这个的问题。$("[name=‘yw1_c1[]’]")

折腾一下 JQuery 的选择器。

感谢你的回复


$("[name='yw1_c1[]']")

这个地方有问题???我再试下

我换了几种方式,用jquery去取,不过还是不行 :unsure:

你这样应该是不行的。因为只是第一页的数据绑定了click事件,翻页之后,貌似就不会有效了。你应该将 click 写成函数,手工绑定到 Checkbox 中去。

哦,是的,突然开朗起来了,是应该写个函数的,这样当跳转到下一页时就可以取到值了,谢谢你呀! :rolleyes: