Sencha Touch:用于创建/更新功能的ScriptTagProxy网址 [英] Sencha Touch: ScriptTagProxy url for create/update functionality

查看:105
本文介绍了Sencha Touch:用于创建/更新功能的ScriptTagProxy网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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
            },}

如您所见,指定了一个网址。
但我仍然收到错误消息:
未捕获错误:您正在使用ServerProxy但未提供url。
);

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. );

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

Same behaviour when using AjaxProxy or RestProxy for example :(

推荐答案

Hering,

第一块把你编码为k:

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

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

答案是肯定的。

问题2)如果是:行动如何应用于网址?

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

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

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();

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

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

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

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.

这篇关于Sencha Touch:用于创建/更新功能的ScriptTagProxy网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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