Posts mit dem Label Bug werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Bug werden angezeigt. Alle Posts anzeigen

Dienstag, 20. Dezember 2011

Sencha Touch 1.1 - Adding a record and removing it doesn't work

I did the following and it worked well:
Add an entry - reload the app - delete that entry

I did the following and it didn't work:
Add an entry - delete that entry

Why?
I started to debug both cases paralelly. In both cases I found the new record in the object that is used to determine what has to be done, but for some strange reason in the case of adding and directly deleting that entry Sencha Touch doesn't find the entry. 

What I did is really simple: After running the store.remove(record) method I check if there's a record in the store.removed property. If not, I add that record manually. You can as well fully remove the store.remove(record) method call and write the record directly into the property. It's up to you.

After you did that you just need to call
store.destroy() to remove the record.

Sencha Touch 1.1 - CRUD actions & callbacks via REST proxy

CRUD actions
Methods without value param (update, destroy):
store.update({
    callback: function(answer, object, success) {
        if (success) { ... }
    }
});

store.destroy({
    callback: function(answer, object, success) {
        if (success) { ... }
    }
});


Methods with value param (create, load):
store.create(values, {
    callback: function(answer, object, success) {
        if (success) { ... }
    }
});

store.load({
    callback: function(answer, object, success) {
        if (success) { ... }
    }
});


CRUD action executes only once?
If you can run some of these functions once and after that no XHR is made, it may be because you encountered this bug: Bug @ Sencha Forum

I solved this bug by setting store.snapshot to false, so the function that engages the XHR is no longer looking for changes in the snapshot but in the store object.