保存基于Dgrid JsonRest的商店 [英] Saving a Dgrid JsonRest-based Store

查看:63
本文介绍了保存基于Dgrid JsonRest的商店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有可编辑日期字段的grid。在其上方,我有一个保存按钮,该按钮调用 grid.save 。当我按下按钮时,它会向存储目标发出XHR请求,但不会将任何数据返回给服务器以供我保存(即POST为空)。现在,很难查询ID为1900的项目,如下面的代码所示。



这里是商店的启动方式:

  var store = new JsonRest({
target: / safari / resources / 1900 / calendarObjects /,
sortParam: sort,
id属性: id,
属性:{
startDate:{
格式: date-time
},
endDate:{
格式: date-time
}
}
});

这是网格:



<上课= lang-javascript prettyprint-override> var grid = new声明([OnDemandGrid,dgridEditor,键盘,选择,DijitRegistry])({
store:store,
查询: {responseType: json},
bufferRows:40,
loadingMessage: Loading ...,
列:[
{field: oid,标签:对象ID},
dgridEditor({field: startDate,名称: Start Date,editorArgs:{选择器:'date',datePattern:'yyyy-MM-dd',语言环境:'en-us '}},DateTextBox),
dgridEditor({字段: startTime,名称:开始时间}},TimeTextBox, click),
dgridEditor({field: endDate,名称: End Date},DateTextBox, click),
dgridEditor({field: endTime,名称: End Time},TimeTextBox, click),
{field: endDateOid ,标签: End OID}
],
}, grid);

保存按钮如下所示:

  registry.byId( saveButton)。on( click,function(){
grid.save();
});

就像我说的那样,单击保存后,将触发一个新的XHR请求,但是如果将任何数据发送回服务器,我不确定它的去向。我让后端打印了它收到的所有HTTP标头,但什么也没看到。



更新(2013年1月2日):升级后的服务器后端使用传统的RESTful URL,这似乎使Dojo更加满意,但仍使用 GET 代替 PUT 并且无法实际发送任何要保存的内容。



更新(2013年1月5日):有什么原因导致JsonRest会调用在调用PUT之前先获取?我想知道我的程序在愿意执行PUT之前是否需要返回某些数据(因此问题不在于GET,而是接下来发生的一切)...但是,这完全是推测。我已经死胡同了。

解决方案

我不确定这是否行得通,可以看看 https://github.com/SitePen/dgrid/blob/master/test/JsonRest.html

  window.grid = new(declare([Grid,Selection,Keyboard]))({
store:testStore,
getBeforePut:false,
列:columns
}, grid);

,您可以尝试设置属性 getBeforePut 改为 false


I have a dgrid that has editable date fields. Above it, I have a "Save" button that calls grid.save. When I hit the button, it makes an XHR request back to the store's target, but does not provide any data back to the server for me to save (i.e. POST is empty). Right now it is hardwired to query item id 1900, as you can see in the code below.

Here is how the store is initiated:

  var store = new JsonRest({
    target: "/safari/resources/1900/calendarObjects/",
    sortParam: "sort",
    idProperty: "id",
    properties: {
        startDate:{
            format: "date-time"
        },
        endDate:{
            format: "date-time"
        }
    }
  });

And here is the grid:

        var grid = new declare([OnDemandGrid, dgridEditor, Keyboard, Selection, DijitRegistry])({
            store: store,
            query: {responseType: "json" },
            bufferRows: 40,
            loadingMessage: "Loading...",
            columns: [
                {field: "oid", label: "Object ID"},
                dgridEditor({field: "startDate", name: "Start Date", editorArgs: { selector: 'date', datePattern: 'yyyy-MM-dd', locale: 'en-us' }}, DateTextBox),
                dgridEditor({field: "startTime", name: "Start Time"}, TimeTextBox, "click"),
                dgridEditor({field: "endDate", name: "End Date"}, DateTextBox, "click"),
                dgridEditor({field: "endTime", name: "End Time"}, TimeTextBox, "click"),
                {field: "endDateOid", label: "End OID"}
            ],
        }, "grid");

The save button looks like this:

registry.byId("saveButton").on("click", function (){
    grid.save();    
 });

Like I said, after I click "save," a new XHR request fires, but if it is sending any data back to the server, I'm not sure where it is going. I had my backend print up all of the HTTP headers it received and didn't see anything.

UPDATE (January 2, 2013): Upgraded server backend to use a traditional RESTful URL, which seems to make Dojo slightly happier, but it still is using GET instead of PUT and fails to actually send anything to save.

UPDATE (January 5, 2013): Is there any reason why JsonRest would call GET before calling PUT? I'm wondering if my program needs to return certain data before the program is willing to go do the PUT (and thus the problem isn't the GET but whatever comes next)... But, this is entirely speculation. I've reached a dead end.

解决方案

I'm not sure whether this will work, you can have a look at https://github.com/SitePen/dgrid/blob/master/test/JsonRest.html

                window.grid = new (declare([Grid, Selection, Keyboard]))({
                    store: testStore,
                    getBeforePut: false,
                    columns: columns
                }, "grid");

and you can try to set the property getBeforePut to false.

这篇关于保存基于Dgrid JsonRest的商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆