Вопрос

I'm new to Sencha Touch and I'm having problems to delete a record.

This is my model:

Ext.define('MyApp.model.Customer', {
    extend: 'Ext.data.Model',
    ...
    config: {
        idProperty: 'key',
        fields: [
            {
                name: 'key',
                type: 'auto'
            },
            {
                name: 'name',
                type: 'string'
            }
            ...
        ]
    }
    ....
}

and this is an event associated with a delete customer button:

onDeleteCustomerBtnTap: function(button, e, eOpts) {
    var data = this.getCustomerDetail().getData();
    var store = Ext.getStore("CustomerStore");
    var record = store.getById(data.key);
    store.remove(record);
    store.sync();
}

EDIT:

this is the store

proxy: {
        type: 'rest',
        url: 'http://example.com/customers',
        useDefaultXhrHeader: false,
        appendId: false,
        reader: {
            type: 'json',
            idProperty: 'key',
            rootProperty: 'data'
        },
        writer: {
            type: 'json'
        }
    }

The problem is when it tries to sync the store. The request url is http://example.com/customers?_dc=1394840324234 instead of http://example.com/customers/10?_dc=1394840324234.

What am I doing wrong?

Это было полезно?

Решение

I finally used the erase method of Ext.data.Model. Here is my final version:

var data = this.getCustomerDetail().getData();
var store = Ext.getStore("CustomerStore");
var record = store.getById(data.key);

record.erase({
    success: function() {
        // ...
    }
}

});

Другие советы

are you defining your proxy as 'rest' and not 'ajax'?

proxy: {
    type: 'rest',
    url : '/users'
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top