gpt4 book ai didi

javascript - 我可以重写 dojo/store/JsonRest API 方法吗?

转载 作者:行者123 更新时间:2023-11-28 08:43:16 28 4
gpt4 key购买 nike

Dojo dojo/store/JsonRest API Reference

请查看Method and RESTful Mapping Section

那里写着我的服务器应该遵循 RFC 2616 与商店交互。我可以通过某种方式覆盖标准方法来使用不同的实现吗?怎么办?

最佳答案

您可以扩展 JsonRest Store 以允许自定义请求对象并覆盖其方法,我已经对其进行了自定义并在我的项目中使用了它。我将其放在单独的 CutomizeJSonRestStore.js 文件中

   require([
"dojo/_base/declare", "dojo/parser", "dojo/ready",
"dojo/data/ObjectStore", "dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
], function (declare, parser, ready, ObjStore, JsonRest, Memory, Cache) {
declare("ServerSideStore", [ObjStore], {
constructor: function(args) {
/* jason source that will talks with server, set sort parametere to be read from server to know to sort according to what*/
jasonRest = JsonRest({
target : this.target,
sortParam : "sortParam"
});



/* cach store to make calls at cleint side if possible */
cacheStore = new Cache(jasonRest, new Memory());
this.objectStore = cacheStore;
declare.safeMixin(this, args);
},

/*
send request to server side to update an item
*/
onSet : function (item, attribute, old, value) {
dojo.xhrPost({
url : this.target + "?rsourceRequest=update&attributeParam=" + attribute + "&newValueParam=" + value,
postData : dojo.toJson(item),
handleAs : "json",
headers : {
"Content-Type" : "application/json"
},
});
},

/*
send request to server side to create new item
*/
onNew: function(newItem, parentInfo) {
dojo.xhrPost({
url : this.target + "?rsourceRequest=create&attributeParam",
postData : dojo.toJson(item),
handleAs : "json",
headers : {
"Content-Type" : "application/json"
},
});
},

/*
send request to server side to delete an item
*/
onDelete: function(deletedItem) {
dojo.xhrPost({
url : this.target + "?rsourceRequest=delete",
postData : dojo.toJson(item),
handleAs : "json",
headers : {
"Content-Type" : "application/json"
},
});
}

});

});

dojo-jsonreststore more here DOJO-JSON REST

关于javascript - 我可以重写 dojo/store/JsonRest API 方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20236790/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com