使用JsonRestSore和Zend Framework的dojo DataGrid

时间:2012-06-08 13:19:09

标签: dojox.grid.datagrid

我试图在数据网格中显示从REST服务器(在Zend Framework中实现)中检索到的一些json数据。问题是数据网格只显示“正在加载......”而且没有其他事情发生。 在Firebug Lite中,我可以看到执行GET请求并且响应正常。 数据仍未在数据网格中呈现,非常令人困惑。

基本上,我从“将商店连接到DataGrid”中复制'n'pasted this code,只是替换了目标网址和结构以适应我的REST API。

我正在使用Dojo 1.7.2和Zend Framework 1.11.11

这是我的index.phtml文件。

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Demo: Connecting DataGrid to a Store</title>

        <link rel="stylesheet" href="/js/dojo/dojox/grid/resources/claroGrid.css" media="screen">
        <!-- load dojo and provide config via data attribute -->
        <script type="text/javascript" src="/js/dojo/dojo/dojo.js"
                data-dojo-config="isDebug: true,parseOnLoad: true">
        </script>
        <script>
            dojo.require("dojo.store.JsonRest");
            dojo.require("dojo.store.Memory");
            dojo.require("dojo.store.Cache");
            dojo.require("dojox.grid.DataGrid");
            dojo.require("dojo.data.ObjectStore");
            dojo.ready(function(){
                myStore = dojo.store.Cache(dojo.store.JsonRest({target:"api/testresults/"}), dojo.store.Memory());
                grid = new dojox.grid.DataGrid({
                    store: dataStore = dojo.data.ObjectStore({objectStore: myStore}),
                    structure: [
                        {name:"Test case", field:"testCase", width: '25%'},
                        {name:"Verdict", field:"verdict", width: '25%'},
                        {name:"Device under test", field:"deviceUnderTest", width: '25%'},
                        {name:"Test environment", field:"environment", width: '25%'}
                    ]
                }, "target-node-id"); // make sure you have a target HTML element with this id
                grid.startup();
                });
        </script>
    </head>
    <body>
        <h1>Demo: Connecting DataGrid to a Store</h1>
        <div id="target-node-id"></div>
        </body>
</html>

JsonRestStore在Firebug Lite中出现的GET请求:

ResponseHeaders
Date    Fri, 08 Jun 2012 12:59:41 GMT
X-Powered-By    PHP/5.3.8
Content-Range   items 0-24/2
Connection  Keep-Alive
Content-Length  229
Server  Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
Content-Type    application/json
Keep-Alive  timeout=5, max=73

RequestHeaders
Accept  application/javascript, application/json
Range   items=0-24
Content-Type    application/x-www-form-urlencoded
X-Requested-With    XMLHttpRequest

这是GET请求的结果的JSON数据

[ { "deviceUnderTest" : "R1B583",
        "environment" : "Example1",
        "id" : "1",
        "testCase" : "COH901359_12_001_001",
        "verdict" : "FAIL"
      },
      { "deviceUnderTest" : "R1B583",
        "environment" : "Example2",
        "id" : "2",
        "testCase" : "COH901359_12_001_002",
        "verdict" : "PASS"
      }
    ]

1 个答案:

答案 0 :(得分:1)

似乎实际上Firebug Lite(谷歌浏览器)阻止数据网格显示数据......一旦我禁用它,数据就会按预期呈现。