2012-04-12 43 views
0

我試圖按照這裏的教程:道場:DataGrid中從JsonRest商店

http://dojotoolkit.org/documentation/tutorials/1.7/store_driven_grid/

教程寫道:

require(["dojo/store/JsonRest"], function(JsonRest){ 
myStore = new JsonRest({target:"MyData/"}); 

我MyData.json文件放在ROOT \邁德特。如果我運行下面的代碼

... 
<script> 
var myStore, dataStore, grid; 
require(["dojo/store/JsonRest"], function(JsonRest){ 
    myStore = new JsonRest({target:"MyData/"}); 
}); 

require(["dojox/grid/DataGrid", 
     "dojo/data/ObjectStore", 
     "dojo/domReady!" 
], function(DataGrid, ObjectStore){ 
     grid = new DataGrid({ 
     store: dataStore = ObjectStore({objectStore: myStore}), 
     structure: [ 
      {name:"State Name", field:"name", width: "200px"}, 
      {name:"Abbreviation", field:"abbreviation", width: "200px"} 
     ] 
     }, "target-node-id"); // make sure you have a target HTML element with this id 
     grid.startup(); 
}); 
</script> 
... 

我得到的數據404錯誤,如果我寫的「邁德特/」和416(要求的範圍不合適),如果我把「邁德特/ MyData.json」。

我知道這是什麼那麼傻,因爲我無法找到任何人有同樣的問題,但我無法看到的解決方案:/

最好的問候,並感謝您的幫助!

安德烈亞斯

+1

url應該指定json文件MyData/MyData.json。你可以通過直接訪問url來檢索帶瀏覽器的json文件嗎? – 2012-04-12 14:22:30

+0

該演示中的jsonData的URL是http://dojotoolkit.org/documentation/tutorials/1.7/store_driven_grid/demo/MyData/ ,但它內部有一個圖像,它也沒有完整的url。 – OammieR 2012-04-12 15:09:34

+0

謝謝你的回覆!克雷格:如果我指定這樣的網址,我會得到416錯誤。如果我點擊Chromes調試器中請求的鏈接,我會得到正確的JSON。 OammierR:如果我刪除圖像,它是相同的錯誤(如果我按照教程編寫整個路徑,則爲416)。如果我寫完整路徑,它是一樣的(例如localhost:8080/Data/...) – andreasnauta 2012-04-13 08:24:40

回答

1

好了,所以您提供的數據還不足以確定什麼問題,但404沒有找到。

所以:

  1. 確保您可以通過瀏覽器訪問JSON文件沒有問題。
  2. 如果是這樣,請使用{target:「http:// URL」}中的此URL,這應該起作用。
  3. 請記住,在dojo.store.JsonRest目標選項{target:「relative or absolute」}中,如果使用相對路徑,它將查看執行腳本的路徑。

例如如果您的網格腳本位於http:// localhost/grid/,則JsonRest將相對於此路徑。對於目標{目標: 「MyData.json」}它將在HTTP://localhost/grid/MyData.json,沒有找到它,如果它在HTTP其中://localhost/MyData.json

如果你仍然不能解決這個帖子了!

+0

謝謝您的回覆!如果我這樣做'myStore = new JsonRest({target:「http:// localhost:8080/Workspace/MyData/Data.json」});'我得到一個416,(Requested Range Not Satisfiable)。我可以在瀏覽器中使用該URL查看JSON,因此Dojo和數據之間存在「連接」。數據是有效的JSON,所以我不知道我做錯了什麼。 – andreasnauta 2012-04-16 06:54:20

+0

我使用了你粘貼的代碼,並且一切都很完美,所以證明你的問題與數據有關,可以證明它的結構。 JsonRest的數據結構: [{name:'Florida',簡稱:'FL'},{名稱:'California',簡稱:'CL'}] – Jmsegrev 2012-04-16 13:27:02