• yii gii自动生成的curd添加批量删除实例


    1.在视图中 CGridView中的columns添加,作用是添加多选框

     代码如下 复制代码

    array(
           'selectableRows' => 2,
           'footer' => '<button type="button" onclick="GetCheckbox();" style="76px">批量删除</button>',
           'class' => 'CCheckBoxColumn',
           'headerHtmlOptions' => array('width' => '33px'),
           'checkBoxHtmlOptions' => array('name' => 'selectdel[]'),
         ),

    2.引入js代码

     代码如下 复制代码
    function GetCheckbox(){
                var data=new Array();
                $("input:checkbox[name='selectdel[]']").each(function (){
                        if($(this).attr("checked")==true){
                                data.push($(this).val());
                        }
                });
                if(data.length > 0){
                        $.post("index.php?r=member/my_cart/delall",{'selectdel[]':data}, function (data) {
                                if (data=='ok') {
                                        alert('删除成功!');
              location.href = "index.php?r=member/my_cart/admin";
                              }
                        });
                }else{
                        alert("请选择要删除的选项!");
                }
        }

    3.Action

     代码如下 复制代码

    public function actionDelall() {
            if (Yii::app()->request->isPostRequest) {
                $criteria = new CDbCriteria;
                $criteria->addInCondition('rec_id', $_POST['selectdel']);
                Cartdb::model()->deleteAll($criteria);
                if (isset(Yii::app()->request->isAjaxRequest)) {
                    echo 'ok';
                }
                else
                    $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
            }
            else
                throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
        }

  • 相关阅读:
    自定义、操作cookie
    云中沙箱学习笔记2-ECS之初体验
    云中沙箱学习笔记1-快速部署并使用MySQL数据库
    练习小程序
    理解Thread.sleep()函数
    排序:冒泡排序;直接选择排序;反转排序
    float和double
    BigDecimal
    Linux学习笔记5(2)-CentOS7中Tomcat8修改jvm内存配置
    ret2dl学习笔记
  • 原文地址:https://www.cnblogs.com/9axin/p/6243685.html
Copyright © 2020-2023  润新知