如何将django休息框架json查询结果连接到dgrid / OnDemandGrid [英] How do I connect a django rest framework json query result to dgrid/OnDemandGrid
问题描述
我的JSON商店(django rest框架)返回count,next,previous和results的键。
My JSON store (django rest framework) returns keys for "count", "next", "previous", and "results".
count
next是下一页结果的网址(例如ids 26-50)。
"next" is the url for the next page of results (e.g. ids 26-50).
previous是上一页结果的网址(在这种情况下为null,因为这是结果的第一页)。
"previous" is the url for the previous page of results (null in this case since this is the first page of results).
结果键包含我想在OnDemandGrid中显示的实际数据对象。
The "results" key contains the actual data objects I'd like to display in the OnDemandGrid.
如何将结果密钥数据集合连接到网格?谢谢你提前的帮助。
How do I connect the "results" key data collection to the grid? Thank you for your help in advance.
返回的JSON(集合:新的Rest({target:'/ api / events'?format = json'),}) )看起来像这样:
The returned JSON ( collection: new Rest({target: '/api/events'?format=json'),}) ) looks like this:
{
"count":1411,
"next":"http://localhost/api/events/?format=json&page=2",
"previous":null,
"results": [
{"id":1,"event_type":"02","event_at":"2015-03-31T12:53:41Z","machine_id":1,"revs":4342,"color":5,"heads_info":"using http","tag":1,"hidden":false},
{"id":2,"event_type":"02","event_at":"2015-03-31T12:53:41Z","machine_id":1,"revs":4342,"color":5,"heads_info":"using http","tag":1,"hidden":false},
...
{"id":25,"event_type":"02","event_at":"2015-03-31T12:54:01Z","machine_id":1,"revs":4342,"color":5,"heads_info":"using http","tag":1,"hidden":false},
]
}
推荐答案
看起来您正在尝试使用 dsto re / Rest
,但是对服务器请求和响应有一些特定的期望:
It looks like you're trying to use this service with dstore/Rest
, but that has some specific expectations of the server request and response:
- 响应必须报告项目列表以下列方式之一:
- 回应顶级的项目数组
- 回应一个对象,
项目
属性,其值为项目数组
- The response must report the list of items in one of the following ways:
- Respond with a top-level array of items
- Respond with an object with an
items
property whose value is an array of items
- 如果响应是一个对象,您可以包含一个
总计
对象中的属性 - 否则,您必须包含
内容范围
标题(格式为XY / Z项目
,其中Z
是最重要的)
- If the response is an object, you may include a
total
property in the object - Otherwise, you must include a
Content-Range
header (in the formatX-Y/Z items
, where theZ
is of primary importance)
- 开始和计数GET参数(指定为存储在通过
rangeStartParam
和rangeCountParam
) - 范围标题(通过设置
useRangeHeaders:true
) - 否则,默认情况下,商店将通过
限制
GET参数格式为limit(count,start)
(或只是limit(count)
如果开始
为0)
- start and count GET parameters (specified to the store instance via
rangeStartParam
andrangeCountParam
) - Range headers (by setting
useRangeHeaders: true
) - Otherwise, by default, the store will pass a
limit
GET parameter in the formatlimit(count,start)
(or justlimit(count)
ifstart
is 0)
不能满足这些要求(例如对于测距来说,听起来好像有不同的要求,因为它使用了页面),您将需要考虑扩展/实现自定义商店。
If your server can't fulfill these requirements (e.g. it sounds like it has quite different requirements regarding ranging, since it uses pages instead), you're going to need to think about extending/implementing a custom store.
这篇关于如何将django休息框架json查询结果连接到dgrid / OnDemandGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!