2015-05-26 51 views
0

Im有extjs 4.2中的网格下面的商店和模式。删除/修改/添加记录从extjs商店

Ext.define('myapp.store.myStore',{ 
extends:'Ext.data.Store', 
modal:'myapp.modal.myModal', 
storeId:'myGridStore', 
data:[],//used this only when trying inline data 
proxy: { 
type:'memory', 
reader:{ 
type:'json', 
} 
} 

}); 
Ext.define('myapp.modal.myModal',{ 
extends:'Ext.data.Modal', 
fields:['bla','blha'] 
}); 

映射到网格,商店和模式看起来很好,数据填充正确加载到网格中。

问题是,当有修改店里像

grid.getStore().removeAt(rowIndex) 

grid.getStore().add(record) 

IM无法得到那些通过

getRemovedRecords() 

getNewRecords() 

当我将数据加载到店与

grid.getStore().loadData(ajaxCallResponse). 

它工作正常,当我给数据内嵌。

请帮助我了解什么即时做错了......

回答

0

尝试store.getModifiedRecords()代替。这将为您带来新的和编辑过的记录。要检查它是否有新记录,只需检查记录“幻影”属性即可。

另外,如果getNewRecords()和getRemovedRecords()不返回任何记录,请在添加/删除记录后尝试store.sync()。

+0

嗨..感谢您的回应... getModifiedRecords()总是返回存储中的所有记录,并且所有记录的phanthom都是false。在添加或修改后尝试同步,甚至在第一次将数据从extjs ajax call..but载入商店后getNewRecords()和getRemovedRecords()始终为空。 – CARTIC

1
if(record.phantom != true){ 
    record.phantom = true; 
} 
store.loadData(record); 

检查幻象是真的第一次那么loadData,并尝试使用store.getNewRecords(),如果幻象是真实的,只有记录将在那里在getNewRecords()。

0

向商店添加新记录时,为了使getModifiedRecords()方法实际列出这些新添加的记录,必须将phantom属性设置为true(正如@Naren Sathya在先前回答中所建议的那样):

// Create a new default record 
var newServerConfig = new App.model.mConfigServer({ 
    id: idForNewRecord, 
    server: 'server', 
    port: 8443, 
    username: 'user', 
    password: '' 
}); 

/* Setting the phantom property to 'true' will ensure this record will be listed 
* when trying to retrieve those new records with store.getModifiedRecords() later on 
*/ 
newServerConfig.phantom = true; 

// Add it to the store 
storeServers.add(newServerConfig);