从extjs商店删除/修改/添加记录

时间:2015-05-26 13:11:05

标签: extjs4.2 extjs-mvc extjs-grid extjs-stores

我在extjs 4.2中有一个网格的下面存储和模态。

    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)

我无法通过

获取
getRemovedRecords()

getNewRecords()

当我使用

将数据加载到商店时
grid.getStore().loadData(ajaxCallResponse).

当我以内联方式提供数据时,它工作正常。

请帮助我理解我做错了什么......

3 个答案:

答案 0 :(得分:1)

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

首先检查幻影是否为真,然后尝试使用store.getNewRecords(),如果幻像为真,则只有记录将存在于getNewRecords()中。

答案 1 :(得分:0)

尝试使用store.getModifiedRecords()。这将获得新的和编辑的记录。检查它的新记录是否只是检查记录"幻像"属于真实的财产。

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

答案 2 :(得分:0)

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

// 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);
相关问题