除了遍历商店中的记录并检查脏标志之外,还有更清洁的方法吗?
编辑
我正在使用ExtJS4,顺便说一句.
这是返回数据的片段.注意到有一个dirty: true与modified目标集(这实际上是旧的数据和所述data对象包含新数据)
data: Ext.Class.Class.newClass
items: Array[3]
0: Ext.Class.Class.newClass
data: Object
incidentCount: 14
incidentKey: "5466BD05-E4DD-4C1F-9F73-61ABAC6D3753"
dirty: true
id: "Ext.data.Store.ImplicitModel-TEDetailIncidencesStore-ext-record-13"
index: 0
internalId: "ext-record-13"
modified: Object
incidentCount: 7
Run Code Online (Sandbox Code Playgroud)
请注意,该data块包含incidentCount14.这是NEW值,modified块包含OLD值7.
编辑2
我加载商店:
TimeEntryDetailsStore.load({
params:{
timeEntryKey:"myKey"
}
});
Run Code Online (Sandbox Code Playgroud)
激活后,上面的商店成功加载了3行.然后,当我更改一个值时,脏标志被设置,你得到上面的数据块
谢谢
编辑3
这是我要使用的代码,除非有人有更好的方法.我不明白为什么getUpdatedRecords()返回一个空数组.但是哦,好吧.
for(c=0; c < TEDetailIncidencesStore.count(); c++ ) {
if( TEDetailIncidencesStore.data.items[c]["dirty"] == true) {
var dirtyRecord = TEDetailIncidencesStore.data.items[c];
updateTEDetailIncidences(dirtyRecord);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 8
技巧是商店读者需要指定一个idProperty或所有行都被认为是新的.这是为我工作的结构:
Ext.define('Sites', {
extend: 'Ext.data.Model',
fields: [
{name: 'inCphr', type: 'boolean'},
{name: 'department', type: 'string'},
{name: 'commune', type: 'string'},
{name: 'clinic', type: 'string'},
{name: 'sitecode', type: 'int'},
{name: 'dbsite', type: 'int'},
{name: 'ipAddress', type: 'string'},
{name: 'network', type: 'string'},
{name: 'lastChanged', type: 'date'}
]
});
var store = Ext.create('Ext.data.Store', {
model: 'Sites',
proxy: {
type: 'ajax',
url : 'getHaitiSites.php?task=get',
reader:{
type:'json',
root: 'results',
idProperty: 'sitecode'
}
}
});
Run Code Online (Sandbox Code Playgroud)
如果你可以得到一个网格来显示'脏'元素,那么store.getUpdatedRecords().length将是> 0.我看到一条评论建议这只适用于json阅读器,但我不明白为什么它不会也适用于其他数据结构.