jQuery easyui 结合ThinkPHP使用,关于读取数据显示问题

WBOY
Release: 2016-06-23 13:55:42
Original
1176 people have browsed it

原来项目写了一个EasyUI类,里面写了一个datagrig()方法
 public function _datagrid($tag) {
        $id    = !empty($tag['id']) ? $tag['id'] : strtolower(CONTROLLER_NAME.'_'.ACTION_NAME.'_datagrid');
        $style = !empty($tag['style']) ? $tag['style'] : '';
        //默认参数
     $dataOptions = array(
     'border'       => false,
     'fit'          => true,
     'fitColumns'   => true,
     'rownumbers'   => true,
     'singleSelect' => true,
     'pagination'   => true,
         'pageList'     => array(20,30,50,80,100),
         'pageSize'     => cookie('pagesize') ? cookie('pagesize') : C('DATAGRID_PAGE_SIZE'),
     );
     $options = $tag['options'] ? $this->autoBuildVar($tag['options']) : 'array()';
        $fields  = $tag['fields'] ? $this->autoBuildVar($tag['fields']) : 'null';
        
        $parseStr = '

\' style="'. $style .'">';
        $parseStr .= '$arr):if(isset($arr[\'formatter\'])):unset($arr[\'formatter\']);endif;echo "";endforeach;endif; ?>';
        $parseStr .= '
".$key."
';
        
        return $parseStr;
    }
控制器里是这样写的逻辑
$datagrid = array(
                'options'     => array(
                    'title'   => $currentpos,
                    'url'     => U('Uc/pages', array('grid'=>'datagrid')),
                    'toolbar' => 'uc_pages_datagrid_toolbar',
                ),
                'fields' => array(
                    'page'      => array('field'=>'page','width'=>15,'sortable'=>true),
                    'Access'    => array('field'=>'private','width'=>15,'sortable'=>true),
                    '管理操作'    => array('field'=>'id','width'=>15,'formatter'=>'ucPagesOperateFormatter'),
                )
            );


            $this->assign('datagrid', $datagrid);
页面是这样引用标签的,数据就出来了




现在的问题是,这是操作的pages表,里面有字段id ,page ,private,private的值是0或者1,控制器里利用field=》‘private'将0或者1显示到了页面上,但是我们的要求是当数据库privat字段值是0时页面显示public,是1时,页面显示private。不改变表的内容,结构,也就是不动表,怎样操作才能实现呢?请大家帮我看看,谢谢!


回复讨论(解决方案)

我头脑一热,忽然发现,利用跟管理操作那一列的方式显示就能实现,呵呵,解决了!
我在pages页面里定义了一个格式化函数ucPagesAccessFormatter()
//Access格式化
        function ucPagesAccessFormatter(val){
            var btn=[];
            if(val==0){
                return "public";
            }else{
                return "private";
            }
        }
在控制器里写成:
 'fields' => array(
                    'page'      => array('field'=>'page','width'=>15,'sortable'=>true),
                    'Access'    => array('field'=>'private','width'=>15,'formatter'=>'ucPagesAccessFormatter'),
                    '管理操作'    => array('field'=>'id','width'=>15,'formatter'=>'ucPagesOperateFormatter'),
                )
结果页面就显示出来了:

你们谁回复下啊,我好给你们分啊,我给不了自己分啊,不然分全浪费了!

呃,会easyUI,不会php

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template