2012-08-13 25 views
0

我無法將dojo數據網格配置到遠程服務器。我下面的教程的例子是:配置dojo datagrid以使用遠程服務器URL

http://dojotoolkit.org/documentation/tutorials/1.6/populating_datagrid/demo/datagrid-items.html

我的代碼寫在一個單一的JSP和如下所示:

<!DOCTYPE HTML> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <title>Demo: dojox.grid.DataGrid Simple Structure</title> 
     <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/resources/dojo.css"> 
     <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css"> 
     <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/grid/resources/Grid.css"> 
     <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/grid/resources/claroGrid.css"> 


     <!-- load dojo and provide config via data attribute --> 
     <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js" 
       data-dojo-config="isDebug: true,parseOnLoad: true"> 
     </script> 
     <script> 
      dojo.require("dojox.grid.DataGrid"); 
      dojo.require("dojo.data.ItemFileWriteStore"); 

      var grid, store; 
      dojo.ready(function(){ 
       store = new dojo.data.ItemFileWriteStore({ 
        url: "MilestoneAjaxPopulateMsListEditor.json" 
       }); 
         grid = new dojox.grid.DataGrid({ 
          query: { id: "*" }, 
          store: store, 
          structure: [ 
           { name: "First Name", field: "first", width: "25%" }, 
           { name: "Last Name", field: "last", width: "25%" } 
          ] 
         },dojo.byId("grid")); 
         grid.startup(); 
      }); 
     </script> 
    </head> 
    <body class="claro"> 
    <%@ include file="ui_init.jsp" %> 
     <h1>Demo: dojox.grid.DataGrid Simple Structure</h1> 

     <br/> 
     <div id="grid"></div> 
     <%@ include file="footer.jsp" %> 
    </body> 
</html> 

Ajax請求沒有任何錯誤完成(得到200 OK響應碼)。我從遠程服務器收到以下JSON和螢火蟲所示:

{"msdetails":[ 
    {"first":"146", "last":"Concept Commit"} 
, {"first":"147", "last":"Execution Commit"} 
, {"first":"148", "last":"EFT Start"} 
, {"first":"149", "last":"Throttle Pull Review"} 
, {"first":"150", "last":"Throttle Pull"} 
, {"first":"151", "last":"PSIRT Verification"} 
, {"first":"152", "last":"Commit Test"} 
, {"first":"153", "last":"FTS Complete"} 
, {"first":"154", "last":"Image List"} 
, {"first":"155", "last":"Upgrade Planner"} 
, {"first":"156", "last":"Market Matrix"} 
, {"first":"157", "last":"Reg Test Cmp"} 
, {"first":"158", "last":"ISSU CM Creation"} 
, {"first":"144", "last":"Build Start Time"} 
, {"first":"159", "last":"ISSU CM Verification"} 
, {"first":"160", "last":"OPUS"} 
, {"first":"161", "last":"Docs Complete"} 
, {"first":"162", "last":"TAC Readiness"} 
, {"first":"145", "last":"CCO FCS"} 
, {"first":"163", "last":"Field CCO FCS"} 
, {"first":"164", "last":"HPC Date"} 
, {"first":"165", "last":"EoLA"} 
, {"first":"166", "last":"EoS"} 
, {"first":"167", "last":"EoL/EoSM"} 
, {"first":"168", "last":"EoVS Date"} 
, {"first":"169", "last":"End of Support"} 
]} 

我得到的錯誤是:

Dojo Datagrid error

請對這個錯誤的指針幫助。

+0

我能夠通過調整數據網格中兩列的寬度來解決「發生錯誤」消息,以使兩者的寬度都達到100%。但是現在我認爲JSON數據沒有被正確讀取,並且只看到數據網格標題的空白屏幕。 – Sandeep 2012-08-13 12:23:46

回答

1

爲使ItemWriteStore正常工作,您的json的數組部分應該被賦予鍵名作爲「items」,並且您的json對象還需要具有鍵「id」,否則,您還需要指定哪個鍵將充當json對象的ID

{"identifier:"first","items":[ 
    {"first":"146", "last":"Concept Commit"} 
, {"first":"147", "last":"Execution Commit"} 
, {"first":"148", "last":"EFT Start"} 
, {"first":"149", "last":"Throttle Pull Review"}]} 
+0

但是接下來的官方教程是如何工作的:http://dojotoolkit.org/documentation/tutorials/1.6/populating_datagrid/demo/datagrid.html – Sandeep 2012-08-13 11:21:23

+0

已編輯過。感謝您回覆並意識到我的錯誤 – 2012-08-13 14:08:48