Sencha Touch:用于创建/更新功能的 ScriptTagProxy url
我有一个 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 :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Hering,
在您的第一个代码块中,您会问:
问题 1)“我是否必须使用此 url 处理所有操作(读取、更新、创建、删除)?”
答案是肯定的。
问题 2)“如果是:该操作如何应用于 url?”
根据 Sencha 源代码,您需要像这样定义 actionMethods:
});
如果您删除、创建或编辑记录,则必须调用:
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:
});
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.
在这里,
我正在阅读文档这里,我在 Model 类中找到了这个示例:
但是上面您没有显示 app.models.Entry 的模型,您尝试过吗?
Hering,
I was reading the documentation here, I found this example in the Model class:
But above you don't show your Model for app.models.Entry, have you tried that?