2

我有一个问题,萤火虫没有告诉我任何问题:/

我的funcions.js

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

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

Ext.onReady(function() {
    Ext.QuickTips.init();

    // setup the state provider, all state information will be saved to a cookie
    Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));

    var store = Ext.create('Ext.data.Store', {
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'src.php'
        }
    });
    var grid = Ext.create('Ext.grid.Panel', {
        store: store,
        stateful: true,
        collapsible: true,
        multiSelect: true,
        stateId: 'stateGrid',
        columns: [
        {
            text     : 'Nombre Chofer',
            flex     : 1,
            sortable : false,
            dataIndex: 'nombre_chofer'
        }
        ],
        height: 350,
        width: 600,
        title: 'Array Grid',
        renderTo: 'grid-example',
        viewConfig: {
            stripeRows: true,
            enableTextSelection: true
        }
    });
});

我的 src.php (AJAX)

<?php

include_once 'funciones/header_server.php';
include_once 'model/ChoferModel.php';

function getList() {
    $choferModel = new ChoferModel();
    $resultQuery = $choferModel->getTable();
    $conteo = count($resultQuery) - 1;
    $resultQuery = (array) $resultQuery;

    if ($conteo > 0) {
        foreach ($resultQuery as $chofer) {
            $rec['nombre_chofer'] = $chofer['NOMBRE_CHOFER'];
            $arr[] = $rec;
        }
        $jsonresult = JEncode($arr);
        echo $jsonresult;
    }
}

getList();

还有我的 index.php

<?php
//include_once 'funciones/header_server.php';
//include_once 'model/ChoferModel.php';
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Sistema para control de viaticos - COPRA</title>
        <link rel="stylesheet" type="text/css" href="script/ext-all.css" />
        <script type="text/javascript" charset="utf-8" src="script/ext-all-dev.js"></script>
        <script type="text/javascript" charset="utf-8" src="script/ext.js"></script>
        <script src="script/funcions.js"></script>
    </head>
    <body>
        <div id="grid-example" name="grid-example"></div>
    </body>
</html>

我的输出是黑色的,不显示表格或网格...请帮助我..

截图:src 输出:http: //i.stack.imgur.com/zLMgz.png

4

3 回答 3

1

只需定义您自己的模型并在 ajax 代理设置中使用它。

请参阅代码的工作示例

于 2012-05-12T11:19:45.423 回答
0

将代理配置放入模型到存储中。这在我的应用程序中对我有用。

这里我如何配置我的模型:

proxy: {

type: 'ajax',
api: {
    read: 'scripts/receive.php',
    create: 'scripts/create.php?action=create',
    update: 'scripts/create.php?action=update',
    destroy:'scripts/destroy.php?action=destroy'
},

reader: {
    type: 'json',
    root: 'groups'
},

于 2012-05-13T07:20:17.250 回答
0

也许,您必须将 php 中的响应设置为 json。将此添加到您的 php

header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
于 2014-12-15T18:47:03.560 回答