开发者

Sencha Touch: ScriptTagProxy url for create/update functionality

开发者 https://www.devze.com 2023-02-23 22:53 出处:网络
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, delet

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. 开发者_JAVA技巧 );

Same behaviour when using AjaxProxy or RestProxy for example :(


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号