2015-09-22 49 views
0

我想要從商店中刪除多個項目而無需刷新我的頁面時遇到問題。我第一次刪除的事件,一切都很好,你可以從這個小提琴片段看到:ExtJS存儲銷燬事件提交

551 200 HTTP localhost:52543 /api/Appointments/Destroy?_dc=1442940419083 140 no-cache; Expires: -1 application/json; charset=utf-8 chrome:157528   

數據:

{ "Id":1749644,"StartDate":"2015-09-22T01:00:00+02:00","EndDate":"2015-09-22T03:00:00+02:00","ResourceId":9,"PreviousResourceId":0,"Name":"","Cls":""} 

但是,如果我想隨後刪除其他項目(不刷新頁),這是因爲雖然事件存儲不接受或理解的是,以前刪除的記錄已經處理:

[ 
{ Id":1749644,"StartDate":"2015-09-22T01:00:00+02:00","EndDate":"2015-09-22T03:00:00+02:00","ResourceId":9,"PreviousResourceId":0,"Name":"","Cls":""}, 
{"Id":1749656,"StartDate":"2015-09-22T10:45:00+02:00","EndDate":"2015-09-23T16:00:00+02:00","ResourceId":20,"PreviousResourceId":0,"Name":"test","Cls":""} 
] 

如果你仔細觀察,你會看到相同的事件AP梨在第二個電話,但這不應該!除此之外,一切都很完美:每調用一次destroy就會調用Web API(因此在每次請求頁面後首次調用)。第一次調用後,Web API仍被調用,但由於意外輸入,綁定現在已損壞:它收到一個集合,而它只需要一個項目。

這裏是撕:

Ext.define('SchedulerApp.store.EventStore', { 
extend: "Sch.data.EventStore", 
autosync: true, 
batch: false, 
proxy: { 
    type: 'ajax', 
    api: { 
     create: '/api/Appointments/Add', 
     update: '/api/Appointments/Update', 
     destroy: '/api/Appointments/Destroy' 
    }, 
    reader: { 
     type: 'json' 
    }, 
    writer: { 
     type: 'json', 
     writeAllFields: true 
    } 
}, 
listeners: { 
    load: { 
     fn: function (store, records, successfull) { 
     } 
    }, 
    create: { 
     fn: function (store, records, successfull) { 

     } 
    }, 
    add: { 
     fn: function (store, records, successfull) { 
      //store.sync(); 
     } 
    }, 
    update: { 
     fn: function (store, records, successfull) { 
      var previousResource = records.previous.ResourceId; 
      records.data.PreviousResourceId = previousResource; 
      records.store.sync(); 
     } 
    }, 
    destroy: { 
     fn: function (store, records, successfull) { 
     } 
    }, 
    remove: { 
     fn: function (store, records, successfull) { 
      store.sync(); 
     } 
    }  
} 

});

我需要弄清楚如何'接受'更新/插入/刪除記錄。這是一個相當獨立的問題,所以在這裏發佈的其他代碼都是無用的信息。

回答

0

原來我確實錯過了商店的承諾功能。在回調的成功方法中,我添加了提交併且問題消失了!