2013-12-07 41 views
-1

vehicle.jsEXT JS JsOnStore無法網格面板中顯示

Ext.Loader.setConfig({enabled: true}); 
    Ext.Loader.setPath('Ext.ux', 'ux/'); 
    Ext.require([ 
    'Ext.tip.QuickTipManager', 
     'Ext.tree.*', 
     'Ext.data.*', 
     'Ext.window.MessageBox', 
     'Ext.window.*', 
    ]); 
    Ext.onReady(function() { 
     Ext.QuickTips.init(); //tips box 


     Ext.define('MyApp.view.MyGridPanel', { 
     extend: 'Ext.grid.Panel', 
     renderTo: Ext.getBody(), 
     width: window.innerWidth, 
     header: false, 
     height: window.innerHeight, 
     store: UserStore, 

     initComponent: function() { 
      var me = this; 

      Ext.applyIf(me, { 
       columns: [ 
        { 
         xtype: 'gridcolumn', 
         dataIndex: '_id', 
         text: 'Vehicle ID' 
        }, 
        { 
         xtype: 'numbercolumn', 
         width: 126, 
         dataIndex: 'Plat_No', 
         text: 'Plat Number' 
        } 
       ], 
       dockedItems: [ 
        { 
         xtype: 'toolbar', 
         dock: 'top', 
         items: [ 
          { 
           xtype: 'button', 
           cls: '', 
           width: 59, 
           icon: '', 
           iconCls: 'save', 
           text: 'Save' 
          }, 
          { 
           xtype: 'button', 
           cls: '', 
           width: 59, 
           icon: '', 
           iconCls: 'edit', 
           text: 'Edit' 
          } 
         ] 
        } 
       ] 
      }); 

      me.callParent(arguments); 
     } 

    }); 
    var win = Ext.create('MyApp.view.MyGridPanel'); 
    win.show(); 


     Ext.define('VehicleModel', { 
      extend: 'Ext.data.Model', 
      fields: ['_id', 'Plat_No'] 
     }); 

     Ext.override(Ext.data.Connection, { 
     timeout : 840000 
     }); 

     var UserStore = Ext.create('Ext.data.JsonStore', { 
      model: 'VehicleModel', 
      autoLoad: false, 
      proxy: { 
       type: 'ajax', 
       url: 'get-vehicle.php', 
       baseParams: { //here you can define params you want to be sent on each request from this store 
          //groupid: 'value1', 
          }, 
       reader: { 
        type: 'json' 
       } 
      } 
     }); 

     UserStore.load({ 
          params: { //here you can define params on 'per request' basis 
            //groupid: 1, 
            } 
          }) 

    }); // on ready 

得到-vehicle.php

<?php 
mysql_connect("localhost", "root", "123456") or die("Could not connect"); 
mysql_select_db("db_shuttlebus") or die("Could not select database"); 

$parent_id = $_GET['groupid']; 

$query = "SELECT * FROM tbl_vehicle"; 

$rs = mysql_query($query); 

$arr = array(); 
while($obj = mysql_fetch_object($rs)) { 
$arr[] = $obj; 
} 

echo json_encode($arr); 


?> 

但網格面板仍是空白,但螢火蟲像下面這樣返回get-vehicle.php

/localhost/BusTicket/vehicle/get-vehicle.php?_dc=1386449682081&page=1&start=0&limit=25 

ParamsHeadersResponseHTML 

[{"_id":"1","Plat_No":"PKN7711"},{"_id":"2","Plat_No":"AKC1234"},{"_id":"3","Plat_No":"ADB4333"}] 

是什麼問題?

回答

0

在代理的讀者定義您所定義root爲「圖像」

因爲這種配置讀卡器指望JSON格式如下:

{ 
     'images': [ 
     {"_id":"1","Plat_No":"PKN7711"}, 
     {"_id":"2","Plat_No":"AKC1234"}, 
     {"_id":"3","Plat_No":"ADB4333"} 
     ] 
    } 

如果你從你的讀者的配置,讀者刪除root定義應該處理你當前的JSON格式。

+0

不,我已經刪除了根目錄,但仍然無法工作 –

+0

已更新代碼,已將'root' –

0

問題已解決,

因爲UserStore需要在網格面板加載之前加載。 所以,只需修改網格面板前的UserStore即可。完成