好吧,我已经能够使它与DataGrid一起工作,但由于某种原因,Dgrid可能真的令人印象深刻,同时,真的很令人沮丧(许多人推荐它)。到目前为止,我已经能够请求一定数量的数据(只有第一次调用,所以我的请求标头指定返回25项...),一旦我尝试向下滚动以获得更多项目(因此应该发送额外的请求没有任何反应。
基本上这是用jsonrest构建的商店:
define([
"dojo/store/Memory",
"dojo/store/JsonRest",
"dojo/store/Cache",
"dojo/store/Observable"
],
function(
Memory,
JsonRest,
Cache,
Observable
){
var contentMemoryStore = new Memory();
var contentJsonRestStore = new JsonRest({target: "http://dev.mpact.tv:30087/rest/contenus/"});
contentStore = new Cache(contentJsonRestStore, contentMemoryStore);
return new Observable(contentStore);
});
然后,我将此商店传递给OnDemandGrid的属性。
我检查了这个人的例子:http://www.speich.net/articles/demos/jsonrest/dojo-demo-dgrid.php 我检查了dgrid(OnDemandList)的文档:https://github.com/SitePen/dgrid/wiki/Core-Components
添加了请求标头/响应标头(但我认为它们是正确的):
服务器端代码(在perl中):
$r->headers_out->set('Content-Range', sprintf("items %d-%d/%d", $start, $start
+ $num_items - 1, $total));
更新
我使用旧的jsonstore(dojox / data)进行了快速测试:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Statut des canaux générés par Gipsy</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
<style type="text/css">
@import "/dojo/dojo/resources/dojo.css";
@import "/dojo/dijit/themes/tundra/tundra.css";
@import "/dojo/dojox/grid/resources/Grid.css";
@import "/dojo/dojox/grid/resources/tundraGrid.css";
//.grid {
// width: 70em;
// height: 40em;
//}
.Title { text-align: center }
html, body { height: 100%; margin: 0px; font-size: 14px; }
</style>
<script type="text/javascript" src="/dojo/dojo/dojo.js" djConfig="isDebug:false, parseOnLoad: false"></script>
<script type="text/javascript">
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dojox.grid.TreeGrid");
dojo.require("dijit.tree.ForestStoreModel");
dojo.require("dojox.data.JsonRestStore");
dojo.require("dojo.parser");
dojo.addOnLoad(function(){
dojo.parser.parse();
var layout = [
{ name: "Dossier", field: "repertoire", width: "auto" },
{ name: "Fichier", field: "fichier", width: "auto" },
{ name: "Nom", field: "nom", width: "auto" },
{ name: "Date", field: "date", width: "auto" }
];
//var jsonStore = new dojo.data.ItemFileReadStore({ data: dataItems });
//var jsonStore = new dojo.data.ItemFileReadStore({ url: "/cgi-bin/senscity/stingray.json", clearOnClose: true });
var jsonStore = new dojox.data.JsonRestStore({idAttribute: 'id', target: 'http://dev.mpact.tv:30087/rest/contenus'});
var treeModel = new dijit.tree.ForestStoreModel({
store: jsonStore,
query: { type: 'canal' },
rootId: 'canalRoot',
rootLabel: 'Banane',
childrenAttrs: ['children']
});
var grid = new dojox.grid.TreeGrid({
treeModel: treeModel,
structure: layout,
selectable: true,
defaultOpen: false
}, 'programmatic_grid');
grid.startup();
dojo.connect(window, "onresize", grid, "resize");
});
</script>
</head>
<body class="tundra">
<!-- -->
<h1 class="Title" style="margin-bottom: 0.5em;">Statut de la programmation</h1>
<div dojoType="dijit.layout.BorderContainer" style="width: 100%; height: 100%;">
<!--
<div dojoType="dijit.layout.ContentPane" region="top" style="height: 20pt; padding: 0px; border: 0px;">
date de dernière mise à jour, décompte de prochaine mise à jour, bouton de mise à jour, case de désactivation de mise à jour automatique
</div>
-->
<div dojoType="dijit.layout.ContentPane" region="center">
<!-- -->
<div id="programmatic_grid"></div>
<!-- -->
</div>
<!-- -->
</div>
</body>
</html>
所以,我猜它必须是商店或网格。
答案 0 :(得分:5)
请注意,有一个HTTP标头Range
。这表示正在请求的项目。然后在响应中,您需要包含一个Content-Range
标题,该标题描述了返回的项目和可用的总数。
您的回复包含标题:
Content-Range: items=0-24/123456
看起来格式需要:
Content-Range: items 0-24/66
Paging
JsonRest store uses HTTP’s Range header to perform paging. When a request is made for a range of items, JsonRest will include a Range header with an items range unit specifying the range:
Range: items=0-24
On your server, you should look at the Range header in the request to know which items to return. The server should respond with a Content-Range header to indicate how many items are being returned and how many total items exist:
Content-Range: items 0-24/66
答案 1 :(得分:3)
我忘了提到我正在用我的休息框架做跨域请求(也许应该说它......)。
2天后发现,这是我问题的原因(我仍然不知道原因或来源)。当我将代码迁移到服务器时,一切正常。在我的php服务器上做了一个简单的小测试来填充onDemandeGrid并看到它在我的localhost上运行了!
另外,为了绕过跨域,我在服务器端的其余代码上添加了这个标头(继续在跨域开发,直到我们有一个不错的开发环境):
Access-Control-Expose-Headers:Content-Range