ExtJS Store Destroy 事件提交
ExtJS Store Destroy event commit
当我想从商店中删除多个项目而不刷新我的页面时遇到问题。我第一次删除事件时,一切正常,正如您可以从这个 Fiddle 片段中看到的那样:
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":""}
]
如果仔细观察,您会发现第二次调用中也出现了相同的事件,而这不应该!除此之外,一切都很完美:Web API 在每一次 destroy 调用之后被调用(因此是在每次页面请求之后的第一次)。第一次调用后,Web API 仍被调用,但绑定现在由于意外输入而损坏:它收到一个集合,但它只需要 1 个项目。
这是撕裂:
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();
}
}
}
});
我需要弄清楚如何 'accept' 一条 updated/inserted/removed 记录。这是一个相当独立的问题,因此此处发布的所有其他代码都是无用的信息。
原来我确实错过了商城的承诺功能。在回调的成功方法中,我添加了提交,问题消失了!
当我想从商店中删除多个项目而不刷新我的页面时遇到问题。我第一次删除事件时,一切正常,正如您可以从这个 Fiddle 片段中看到的那样:
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":""}
]
如果仔细观察,您会发现第二次调用中也出现了相同的事件,而这不应该!除此之外,一切都很完美:Web API 在每一次 destroy 调用之后被调用(因此是在每次页面请求之后的第一次)。第一次调用后,Web API 仍被调用,但绑定现在由于意外输入而损坏:它收到一个集合,但它只需要 1 个项目。
这是撕裂:
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();
}
}
}
});
我需要弄清楚如何 'accept' 一条 updated/inserted/removed 记录。这是一个相当独立的问题,因此此处发布的所有其他代码都是无用的信息。
原来我确实错过了商城的承诺功能。在回调的成功方法中,我添加了提交,问题消失了!