RIA 服务 JSON 和 Ext.Js

发布于 2025-01-01 21:53:45 字数 672 浏览 4 评论 0原文

我们将 Sencha Ext JS 4 用于我们的 LOB 应用程序。在服务器上,我们使用带有 JSON 端点的 MS RIA 服务(Data Domain 服务)。一般来说,一切正常。但分页却不然。 首先,我们发现 JSON 请求 URL 包含 RIA 简单忽略的关键字(状态、页面等)。经过一番研究,我发现我可以使用以下语法:

例如:

http://localhost/Product/ServiceName.svc/JSON/GetItems?_dc=1328305056811&$take=50&$skip=50

即 $skip(如果您使用 $skip - 您有对 RIA 端的查询进行排序)和 $take,这样的请求会返回适当数量的记录。然而 JSON 响应一开始看起来像这样:

{"GetItemsResult":{"TotalCount":-1,"RootResults":[

即 TotalCount = -1 - 为了使分页正常工作,JS 需要知道记录总数,这是我可以看到它工作的唯一方法 - 如果我使用单独的请求查询记录数并且然后进行页面查询。

问题是我错过了什么吗? RIA 服务有可能返回正确的 TotalCount(如果没有 $skip 或 $take - RIA 服务发回整个表并正确指定 TotalCount)。

We using Sencha Ext JS 4 for our LOB Application. On the server we use MS RIA services ( Data Domain Services ) with JSON endpoint. In general everything working ok.But paging is not.
first of all we discovered that JSON request URL had keywords that RIA simply ignored ( state, page etc. ) after some research I found out that I can use following syntax :

For Example:

http://localhost/Product/ServiceName.svc/JSON/GetItems?_dc=1328305056811&$take=50&$skip=50

i.e. $skip ( if you use $skip - you have to sort query on RIA side ) and $take, request like that return appropriate number of records. However
JSON response looks like this at the beginning:

{"GetItemsResult":{"TotalCount":-1,"RootResults":[

i.e. TotalCount = -1 - in order for paging to work properly JS needs to know total number of records and the only way I can see this working - if I query number of records with separate request and then do page query.

Question is do I miss something ? It is possible for RIA Service to return correct TotalCount ( if there is not $skip or $take - RIA Service send back entire table and specify TotalCount correctly ).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔纱相望 2025-01-08 21:53:45

抱歉,我不太了解您在服务器端使用的技术。我正在使用 Grails,对此我感到非常高兴。所以我对你的总数无法提供太多帮助。

然而,对于分页参数,ExtJS 允许将其期望发送/接收的内容转换为服务器端期望的内容。像这样:

proxy:{
    type: 'ajax',
    url: 'request/my.json',
    //override default param names
    startParam : "offset",
    limitParam :"max",
    sortParam : "sort",
    simpleSortMode:true,//required for directionParam to be used
    directionParam : "order",
    reader: {
        type: 'json',
        root: 'data'
    },

另一个想法:如果您无法使服务器端发送总计数,请在存储上创建一个侦听器并在加载时手动计算记录并将其设置到存储的totalCOunt属性中。

祝你好运。
德米特里.

I am sorry I don't know much about the technology you are using on the server side. I am using Grails and cannot be happier. So I cant help you much with your total count.

However for the paging paramters ExtJS allows for translation of what it expects to send/receive to what your server side expects. Like this:

proxy:{
    type: 'ajax',
    url: 'request/my.json',
    //override default param names
    startParam : "offset",
    limitParam :"max",
    sortParam : "sort",
    simpleSortMode:true,//required for directionParam to be used
    directionParam : "order",
    reader: {
        type: 'json',
        root: 'data'
    },

On another thought: if you cant make your server side send total count, create a listener on the store and count the records manually on load and set it into the totalCOunt property of the store.

Good luck.
Dmitry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文