存储数据未在gridx Grid中填充

时间:2015-08-12 12:51:45

标签: javascript html jsp servlets

  <script type='text/javascript' src='/Firefox/lib/dojo/dojo.js' data-dojo-config="async: true, parseOnLoad: true"></script>
 <link rel="stylesheet" type="text/css" href="/Firefox/lib/dijit/themes/claro/claro.css"> 
      <link rel="stylesheet" type="text/css" href="/Firefox/lib/gridx/resources/claro/Gridx.css">

      <link rel="stylesheet" type="text/css" href="/Firefox/lib/dijit/themes/claro/document.css"> 

<script type='text/javascript'>

var grid;


require({
    packages: [
        {
            name: 'gridx',
           location: '/Firefox/lib/gridx'
        }
    ]
},[
             //Require resources.
             "dojo/dom",
             "dojo/store/Memory",
             "dijit/form/Button",
             "gridx/core/model/cache/Sync",
             "gridx/Grid",
                "gridx/modules/CellWidget",
                  "gridx/modules/SingleSort",
                 "gridx/modules/Pagination",
                 "gridx/modules/pagination/PaginationBar",
              //"gridx/tests/support/stores/QueryReadStore",
                 "dojox/data/QueryReadStore",
             "dojo/domReady!"
         ], function(dom, QueryReadStore, Button,Cache, Grid){

        var store = new dojox.data.QueryReadStore({
            /*   data: [
                { id: 1, feedname: 'Feed4', startstop: 'abc', pause: '', config: ''},
                { id: 2, feedname: 'Feed5', startstop: 'sdf', pause: '', config: ''},
                { id: 3, feedname: 'Feed2', startstop: 'fgh', pause: '', config: ''},
            ]  */ 
                 url:'http://localhost:8080/Firefox/firefox',
                 requestMethod : "get"    

     }); 



        var cacheClass = "gridx/core/model/cache/Sync";

        var structure = [
                         { id: 'feedname', field: 'feedname', name: 'Feed Name', width: '110px'},

                         { id: 'startstop', field: 'startstop', name: 'Start/Stop', width: '61px',}



            ];

             //Create grid widget.
                grid =new  gridx.Grid({
                 id: 'grid',
                 //cacheClass: Cache,
                 store: store,
                 structure: structure,  
                  modules: [
                        "gridx/modules/SingleSort",
                         "gridx/modules/Pagination",
                         "gridx/modules/pagination/PaginationBar"
                           ],
                          paginationInitialPageSize: 5,
                          paginationBarSizes: [1, 2, 3],
                            //paginationBarVisibleSteppers: 2,
                            paginationBarGotoButton: false,
                            paginationBarDescription: true, 

                 autoHeight: true,
                 //columnWidthAutoResize: false

             });

             //Put it into the DOM tree.
             grid.placeAt('compactWidgetGrid');

             //Start it up.
             grid.startup();
             //grid.column("feedname").sort(true);
           //  grid.model.sort([{ colId: 'feedname', descending: true }]);
                    grid.body.refresh();
                 // TODO: I need to make Memory and store global somehow so I can get the data before creating the grid!!
               //  updateGridXData(Memory, store);
         });


function updateGridXData(Memory, store) {

            grid.model.clearCache();

            var appFeedsStore;

            // Create new data store for GridX

            //This line was giving a JavaScript error because appFeedListJSON undefined.
            //Commnent out and uncomment other line to see difference.
           // appFeedsStore = createDataStore(Memory, store, appFeedListJSON);
           // appFeedsStore = createDataStore(Memory, store);

           // grid.setStore(appFeedsStore);

           // grid.model.store.setData(appFeedsStore);

        //    grid.refresh();

            grid.body.refresh();

        //},
        //error: function (error) {
        //    console.log("Inside ERROR");
       // }
    //});    
}


</script>


</head>
<body>

我正在尝试使用 gridx 获取网格。我正在使用dojox / data中的queryreadstore。 如果我使用数据使用硬代码数据:[](我注释掉的部分)它工作正常。但是当我传递url然后它会带来响应,但无法在网格上显示。当数据来自服务器端时,数据不会在网格上填充。 网址&#34; http://localhost:8080/Firefox/firefox&#34;是一个servlet并托管在 tomcat服务器。

Servlet / firefox

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    PrintWriter out= response.getWriter();
    response.setContentType( "application/json");
    out.println("{\"data\":[{\"id\": \"1\", \"feedname\": \"Feed4\", \"startstop\": \"abc\"}]}");
out.flush();
    out.close();
}

我已经尝试了很多天并且还在搜索它,但我无法做到。 您能否建议使用服务器端数据填充 gridx 网格的正确方法。

0 个答案:

没有答案