Sencha Touch:用于创建/更新功能的 ScriptTagProxy url

发布于 2024-10-31 16:34:29 字数 1262 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温馨耳语 2024-11-07 16:34:29

Hering,

在您的第一个代码块中,您会问:

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

答案是肯定的。

问题 2)“如果是:该操作如何应用于 url?”

根据 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.

千里故人稀 2024-11-07 16:34:29

在这里,

我正在阅读文档这里,我在 Model 类中找到了这个示例:

Ext.regModel('User', {
    fields: ['id', 'name', 'email'],

    proxy: {
        type: 'rest',
        url : '/users'
    }
});

但是上面您没有显示 app.models.Entry 的模型,您尝试过吗?

Hering,

I was reading the documentation here, I found this example in the Model class:

Ext.regModel('User', {
    fields: ['id', 'name', 'email'],

    proxy: {
        type: 'rest',
        url : '/users'
    }
});

But above you don't show your Model for app.models.Entry, have you tried that?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文