Sencha Touch: ScriptTagProxy url for create/update functionality

佐手、 提交于 2020-01-03 02:22:17

问题


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:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/5620248/sencha-touch-scripttagproxy-url-for-create-update-functionality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!