2013-11-27 24 views
1

我無法從JsonRest商店填充gridx小部件。查看我的代碼如下: test1.json包含與我在測試庫數據中指定的信息相同的信息。dojo gridx不會讀取JSONRest商店 - 我在這裏失蹤了什麼?

當我將網格更改爲指向測試庫var時,它正確顯示內容,但是當我將它指向reststore變量時,我得到'No items to display'消息。

任何人都知道我錯過了什麼?

var restStore = new dojo.store.JsonRest({target:"http://localhost:9081/MyProj/test1.json"}); 


var teststore = new Store({ 
data: [ 
{id: "1", "description":"First Description"}, 
{id: "2", "description":"Second Description"}, 
{id: "3", "description":"Third Description"}, 
{id: "4", "description":"Fourth Description"} 
     ] 
}); 



    grid = new Grid({ 
    cacheClass: Cache, 
    store: restStore, 
    structure: [ 
     {id: "description", field: 'description', width: '100%'} 
    ] 
    }); 

grid.startup(); 
+1

您是否嘗試過使用實際服務,或僅使用靜態JSON端點?該端點可能不會像dojo/store/JsonRest期望的那樣設置Content-Range標頭,所以這可能是問題的一部分...請參閱http://dojotoolkit.org/reference-guide/1.9/quickstart/ rest.html獲取更多信息。 –

+0

另請注意,您需要使用'Async'緩存('gridx/core/model/cache/Async')。 – twil

+0

其靜態終點....感謝您的鏈接...有沒有quicj的方式來設置內容範圍標題,所以我可以看到它與靜態json工作?... – blu10

回答

0

的gridx和dojox.grid.DataGrid是同樣的事情。 dojox.grid.DataGrid不推薦使用,只適用於傳統的dojo /數據存儲。您可以使用dojo/data/ObjectStore包裝一個道場/店中店與道場/數據API:

var teststore = new ObjectStore({ objectStore: new Store({ … }) }); 

不過,如果你正在開始一個新的項目,你應該使用dgrid代替,這與道場/存儲器存儲的作品本身。

+0

您好,我試圖用gridx控制來做到這一點...只是找到一個很好的例子是非常困難的... – blu10