js文件是怎么加载进去的???

//view/admin.php

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

'id'=&gt;'studentinfo-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),


'filter'=&gt;&#036;model,


'columns'=&gt;array(


    array(


        'name'=&gt;'postdate',


        'value'=&gt;'date(&quot;Y-m-d H:i:s&quot;,&#036;data-&gt;postdate)',


    ),


array(


    'class'=&gt;'CCheckBoxColumn',


        'checkBoxHtmlOptions'=&gt;array(&quot;name&quot;=&gt;&quot;selects[]&quot;),


        'value'=&gt;'&#036;data-&gt;id',


	),


),

)); ?>

我做了一个checkbox多选框,但是每次选一个其他已选中的就没了 永远只能选中一个 郁闷 而且单击每行任何地方也会选中checkbox ~~~oh no~

好像是js的问题,

所以求教,js文件是怎么加载进来的 layout里面的main.php文件里是没有js的,但是查看页面代码就看见页头页尾都有js的了 3q

看一下CGridView的源码就会明白,是通过registerClientScript这个方法把js注册进去的。

我也做过全选,多选。好像用CGridView有些问题。以下是我的代码:


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

	'id'=>'tuan-grid',

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

    'selectableRows'=>2, 

	'columns'=>array(

        array(

			'class'=>'CCheckBoxColumn',

			'header'=>'全选',

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

            'checked'=>'true',

            'htmlOptions'=>array(

                'width'=>'30',

				'style'=>'text-align:center',

             ),

		),

		array(

			'name'=>'rank',

			'htmlOptions'=>array(

                'width'=>'60',

				'style'=>'text-align:center',

             ),

        ),

        array(

			'name'=>'title',

			'htmlOptions'=>array(

                'width'=>'80',

				'style'=>'text-align:center',

             ),

        ),		array(

			'header' => '操作',

			'class'=>'CButtonColumn',

			'htmlOptions'=>array(

				'style'=>'text-align:center',

			),

			'template'=>'{update} {delete}',

		),

	),

)); ?>


<div id="btn" style="width:100%; text-align:right; padding-top:20px"><?php echo CHtml::ajaxLink('批量更新', array('api/create'), array(

    'type'=>'POST',

    'timeout'=>'30000',

    'data'=>'js:{ids:jQuery("input[name=\'tuan-grid_c0\[\]\']:checked").map(function(){ return $(this).val(); }).get()}',

    'beforeSend'=>'function(){ $("#btn").hide(); $("#load").show(); }',

    'success'=>'function(html){ alert(html); }',

    'complete'=>'function(){ $("#btn").show(); $("#load").hide(); }',

    'error'=>'function(a,b,c){ if(b=="timeout") { alert("本次执行过程超过30秒,请分批更新!"); }}', 

));?></div>

<div id="load" style="display: none; text-align:right; width:100%; padding-top:20px">正在更新,请稍后......</div>

谢谢

学习了。

方法create里如何获得选中的id值???

js是通过registerClientScript这个方法引用进去的。

这个问题肯定是自己写个js进去 不用引用的

你问题的最终取向就是CCheckBoxColumn批量删除 批量更新 问题

根据你的需求和我做过的项目

i write like this,hope it‘ll be some help for u.

 view:











    &#60;script type=&quot;text/javascript&quot;&gt;

/<![CDATA[/

var GetCheckbox = function (){

    var data=new Array();


    &#036;(&quot;input[name='selectdel[]']:checked&quot;).each(function (){


           // if(&#036;(this).attr(&quot;checked&quot;)==true){


                    data.push(&#036;(this).val());


           // }


    });


    if(data.length &gt; 0){


            &#036;.post('&lt;?php echo CHtml::normalizeUrl(array('DelSelect'));?&gt;',{'selectdel[]':data},


            		function(){window.location.reload();}


    			);





    }else{


            alert(&quot;请选择要删除的内容&#33;&quot;);


    }

}

/]]>/

</script>

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

'id'=&gt;'leave-grid',


'dataProvider'=&gt;&#036;model-&gt;search_username(),


//'filter'=&gt;&#036;model,


'columns'=&gt;array(


    array(


         'id'=&gt;'id', 


         'class'=&gt;'CCheckBoxColumn',            


         'selectableRows'=&gt;2, 


         'footer'=&gt;'&lt;button type=&quot;button&quot; onclick=&quot;GetCheckbox();&quot; style=&quot;width:76px&quot;&gt;批量删除&lt;/button&gt;',


         'headerHtmlOptions' =&gt; array('width'=&gt;'33px'),


         'checkBoxHtmlOptions' =&gt; array('name' =&gt; 'selectdel[]'),	 


		 'htmlOptions'=&gt;array(    


						'style'=&gt;'text-align:center',


		        )


            ),


	'date',


	'type'=&gt;array(


       'name'=&gt;&quot;类型&quot;,


       'value'=&gt;'(&#036;data-&gt;type==1)?&quot;上午&quot;<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />(&#036;data-&gt;type==2)?&quot;下午&quot;:&quot;整天&quot;)',


	),


	'reasons',


	'username',


    'pass'=&gt;array(


        'name'=&gt;'审核结果',


		'type'=&gt;'html',			


       // 'value'=&gt;'((&#036;data-&gt;pass==1)?&quot;通过:&quot;审核中&quot;)',


		'value'=&gt;'(&#036;data-&gt;pass)?&quot;&lt;img  src=&#092;&quot;images/passed.jpg&#092;&quot; alt=&#092;&quot;通过&#092;&quot; width=&#092;&quot;15&#092;&quot; height=&#092;&quot;15&#092;&quot;&gt;&quot;:&quot;&lt;img  src=&#092;&quot;images/ing.gif&#092;&quot; alt=&#092;&quot;审核中&#092;&quot;&gt;&quot;',


		'htmlOptions'=&gt;array(    


        'style'=&gt;'text-align:center',


           )


	


  	 ), 


 


	array(


	    'header'=&gt;'操作',


		'class'=&gt;'CButtonColumn',


	),


),


)

); ?>

controller:

public function actionDelSelect()


        {


                if (Yii::app()-&gt;request-&gt;isPostRequest)


                {


                        &#036;criteria= new CDbCriteria;


                        &#036;criteria-&gt;addInCondition('id', &#036;_POST['selectdel']);


                        Leave::model()-&gt;deleteAll(&#036;criteria);


                       


                        if(isset(Yii::app()-&gt;request-&gt;isAjaxRequest)) {


                                echo CJSON::encode(array('success' =&gt; true));


                                &#036;this-&gt;redirect(array('/leave/admin'));  


                        } else


                             &#036;this-&gt;redirect(array('/leave/admin'));  


                        	// &#036;this-&gt;redirect(isset(&#036;_POST['returnUrl']) ? &#036;_POST['returnUrl'] : array('index'));


                }


                else


                        throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');


                


        }

rules里面记得申明

array(‘allow’, // allow authenticated user to perform ‘create’ and ‘update’ actions

			'actions'=&gt;array('create','update','delSelect'),//记得申明here


			'users'=&gt;array('@'),


		),

这样就可以全选删除 自动刷新。