Sencha Touch:ScriptTagProxy用于创建/更新功能的URL(Sencha Touch: ScriptTagProxy url for create/update function

编程入门 行业动态 更新时间:2024-10-28 18:23:39
Sencha Touch:ScriptTagProxy用于创建/更新功能的URL(Sencha Touch: ScriptTagProxy url for create/update functionality)

我有一个ScriptTagProxy,我能够收到数据,但现在我想更新一条记录。 我已经指定了一个网址但只有一个网址。 我是否必须使用此网址处理所有操作(读取,更新,创建,删除)? 如果是:操作如何应用于URL? 如果没有:如何指定更多网址?

这是我到目前为止的代码:

app.stores.entries = new Ext.data.Store({ model: "app.models.Entry", storeId: 'app.stores.entries', proxy: { type: 'scripttag', url: 'http://myurl.de/getEntries.php', extraParams: { username: Ext.util.JSON.decode(window.localStorage.getItem('settings')).username, password: Ext.util.JSON.decode(window.localStorage.getItem('settings')).password }, reader: { type: 'json' }, writer: { type: 'json' } } });

我在文档中读到,您可以将配置对象传递给模型的保存功能以配置代理。

所以我试着跟随:

entry.save({ url: 'http://mysite.com/updateEntry.php', extraParams: { username: Ext.util.JSON.decode(window.localStorage.getItem('settings')).username, password: Ext.util.JSON.decode(window.localStorage.getItem('settings')).password, entry: entry },}

如您所见,指定了一个网址。 但我仍然得到错误:未捕获错误:您正在使用ServerProxy但没有提供它的URL。 );

使用AjaxProxy或RestProxy时的相同行为:(

I've a ScriptTagProxy and I'm able to receive the data, but now I wanted to update a record. I've specified an url but only one url. Do I have to handle all the actions (read, update, create, delete) with this url? If yes: how does the action is applied to the url? If not: how I can specify more urls?

Here is the code I have so far:

app.stores.entries = new Ext.data.Store({ model: "app.models.Entry", storeId: 'app.stores.entries', proxy: { type: 'scripttag', url: 'http://myurl.de/getEntries.php', extraParams: { username: Ext.util.JSON.decode(window.localStorage.getItem('settings')).username, password: Ext.util.JSON.decode(window.localStorage.getItem('settings')).password }, reader: { type: 'json' }, writer: { type: 'json' } } });

I've read in the docs that you can pass an config object to the save function of a model to configurate the proxy.

So I tried following:

entry.save({ url: 'http://mysite.com/updateEntry.php', extraParams: { username: Ext.util.JSON.decode(window.localStorage.getItem('settings')).username, password: Ext.util.JSON.decode(window.localStorage.getItem('settings')).password, entry: entry },}

As you see there is a url specified. But I still get the error: Uncaught Error: You are using a ServerProxy but have not supplied it with a url. );

Same behaviour when using AjaxProxy or RestProxy for example :(

最满意答案

赫林,

使用您的第一个代码块,您会问:

问题1)“我是否必须使用此网址处理所有操作(读取,更新,创建,删除)?”

答案是肯定的。

问题2)“如果是:该动作如何应用于网址?”

根据Sencha源代码,您需要定义actionMethods,如下所示:

myApp.stores.Things = new Ext.data.Store({ model: "Things", proxy: { type: 'ajax', actionMethods: { create: 'POST', read: 'GET', update: 'PUT', destroy: 'DELETE' }, url: 'jsontest.json', reader: { type: 'json', root: 'things' } }, autoLoad: true

});

如果您删除,创建或编辑您必须致电的记录:

store.sync();

还有一个“autoSave”属性,但它只在编辑时同步,而不是删除。

这将作为请求有效负载的一部分发送已更改或已删除的内容,您有责任解析json并处理它。

Hering,

With your first block of code you ask:

Question 1) "Do I have to handle all the actions (read, update, create, delete) with this url?"

The answer is yes.

Question 2) "If yes: how does the action is applied to the url?"

According to the Sencha source code you need to define the actionMethods like so:

myApp.stores.Things = new Ext.data.Store({ model: "Things", proxy: { type: 'ajax', actionMethods: { create: 'POST', read: 'GET', update: 'PUT', destroy: 'DELETE' }, url: 'jsontest.json', reader: { type: 'json', root: 'things' } }, autoLoad: true

});

If you delete, create or edit a record you must call:

store.sync();

There is also a "autoSave" property but it only syncs on edits, not removes.

This will send over the things that have changed or been deleted as part of the request payload, it is your responsibility to parse the json and handle it.

更多推荐

本文发布于:2023-08-01 14:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1360391.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   ScriptTagProxy   Sencha   Touch   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!