0

我也使用 EXTJS 进行网格显示和分页。我的问题是网格面板正在显示,但表格内容未显示在网格中。我使用过 php 和 mysql。从表中检索数据的 PHP 代码:

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
define('_PJEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
define('PJPATH', dirname(__FILE__));
define('DB_DIR', PJPATH . DS . 'DB_SETUP');
define('LIB_DIR', PJPATH . DS . 'library');

if (file_exists(PJPATH . DS . 'template.php')) {
    include_once PJPATH . DS . 'template.php';
    include_once PJPATH . DS . 'process.php';
    include_once LIB_DIR . DS . 'factory.php';
}

            $page_num = $_REQUEST['start'];

            $limit=$_REQUEST['limit'];


            $data = PJFactory::getJobAuditDetails();

            $rows= mysql_num_rows($data);

            $result =  PJFactory::displayJobAuditDetail($page_num, $limit);

            while($num_rows=  mysql_fetch_array($result,MYSQLI_ASSOC)){
                $display[]=array('id'=>$num_rows['id'],
                    'id_job_audit'=>$num_rows['id_job_audit'],
                    'error_message'=>$num_rows['error_message']

                );
               }
          $myData = array('errorDisplay'=>$display, 'totalCount'=>$rows);
           echo json_encode($myData);





?>

Java 脚本页面

Ext.require([
    'Ext.grid.*',
    'Ext.data.*'
]);
Ext.onReady(function(){
   // Ext.QuickTips.init();
   var store =new Ext.data.Store({
       proxy: new Ext.data.HttpProxy({
       url: 'processdisplay.php'
      // method: 'GET'  
       }) ,  
     //type: 'ajax',
       reader:  new Ext.data.JsonReader({ 
           type: 'json',
             root:'errorDisplay',
             totalProperty:'totalCount',
             id: 'id'
       },
            [ 
               {name: 'id',mapping: 'id',type: 'int'},

               {name:'id_job_audit',mapping:'id_job_audit',type:'string'},
               {name :'error_message',mapping:'error_message',type:'string'}
         ]
     ),
          autoLoad : true,
           idProperty: 'id'
   });
  // baseParams:{task: "LISTING"}

   var grid = new Ext.grid.GridPanel({

       store: store,

       columns: [

           {header: 'id', width: 30, sortable: true, dataIndex: 'id'},

          // {header: 'id', width: 100, sortable: true, dataIndex: 'id'},

           {header: 'id_job_audit', width: 100, sortable: true, dataIndex: 'id_job_audit'},

           {header: 'error_message', width: 250, sortable: true, dataIndex: 'error_message'}

       ],

       stripeRows: true,

      height:250,

       width:500,

       title:'Job Error Details',
       bbar: new Ext.PagingToolbar({

            pageSize:20,

            store: store,

            displayInfo: true,

            displayMsg: 'Displaying topics {0} - {1} of {2}',

            emptyMsg: "No topics to display"

        })

    });
//store.show();
   store.load();
    // render this grid to paging-grid element
    grid.render('paging-grid');
});

我已经在 firebug 中检查了 echo json_encode($myData) 的结果。它显示正确并在 firebug 中也检查了 JSON 选项,如下所示

errorDisplay
    [Object { id="1", id_job_audit="4", error_message="Missing Category for Pa...avigation Id - 10097374"}, Object { id="2", id_job_audit="4", error_message="Missing Category for Pa...avigation Id - 10097374"}, Object { id="3", id_job_audit="4", error_message="Missing Category for Pa...avigation Id - 10097374"}, 22 more...]

totalCount
    102

我不知道哪里错了。网格是空的,显示消息为“没有要显示的主题”。请说明清楚。

编辑:我已经通过仅对从 db 检索到的结果进行编码进行了测试。当时我在前 25 条记录的网格中显示。即(在我的情况下,echo json_encode($display))

数组结果是否只能在 JSON 中编码?因为在我进入 firebug 作为数组对象之前。

4

1 回答 1

1

读者是代理的属性,而不是商店。此外,您应该使用模型来提供字段。应该看起来像这样(未经测试):

Ext.require(['Ext.grid.*', 'Ext.data.*']);

Ext.define('MyModel', {
    extend: 'Ext.data.Model',
    fields: [{
        name: 'id',
        mapping: 'id',
        type: 'int'
    }, {
        name: 'id_job_audit',
        mapping: 'id_job_audit',
        type: 'string'
    }, {
        name: 'error_message',
        mapping: 'error_message',
        type: 'string'
    }]
});

Ext.onReady(function() {
    var store = new Ext.data.Store({
        model: MyModel,
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'processdisplay.php',
            reader: {
                type: 'json',
                root: 'errorDisplay',
                totalProperty: 'totalCount'
            }
        })
    });
    // baseParams:{task: "LISTING"}

    var grid = new Ext.grid.GridPanel({

        store: store,

        columns: [{
            header: 'id',
            width: 30,
            sortable: true,
            dataIndex: 'id'
        },

        // {header: 'id', width: 100, sortable: true, dataIndex: 'id'},

        {
            header: 'id_job_audit',
            width: 100,
            sortable: true,
            dataIndex: 'id_job_audit'
        }, {
            header: 'error_message',
            width: 250,
            sortable: true,
            dataIndex: 'error_message'
        }],

        stripeRows: true,

        height: 250,

        width: 500,

        title: 'Job Error Details',
        bbar: new Ext.PagingToolbar({

            pageSize: 20,

            store: store,

            displayInfo: true,

            displayMsg: 'Displaying topics {0} - {1} of {2}',

            emptyMsg: "No topics to display"

        })

    });
    //store.show();
    store.load();
    // render this grid to paging-grid element
    grid.render('paging-grid');
});
于 2013-01-28T05:45:13.260 回答