为什么使用this.getStore()。isLoaded()时会导致网格加载循环?
我还注意到我中index_record的每个值都是-1,而我确定store_ca包含id == 1的记录
...
{
xtype: 'gridcolumn',
text: 'Контрагент1',
dataIndex: 'contragent',
flex: 1,
editor: combo,
editor: {
xtype: 'combobox',
displayField:'name',
valueField:'id',
queryMode:'remote',
store: Ext.data.StoreManager.get('ContrAgents'),
},
renderer: function(value, metaData, record, rowIndex, colIndex, store, view){
if(this.getStore().isLoaded()){
store_ca = Ext.data.StoreManager.get('ContrAgents');
index_record = store_ca.findExact('id', 1);
console.log(index_record)
}
if(index_record != -1){
rs = store_ca.getAt(index_record).data;
return rs.name;
}
}
},
...
在store_ca中,存储“ ContrAgents”。 这是我的商店“ ContrAgents”:
var urlRoot = 'data?model=Contragents&method=';
Ext.define('BookApp.store.ContrAgents', {
extend: 'Ext.data.Store',
model: 'BookApp.model.ContrAgents',
autoLoad: true,
storeId: 'ContrAgents',
proxy: {
type: 'ajax',
noCache: false,
actionMethods: {update: 'GET',create: 'GET',destroy: 'GET'},
api: {
create: urlRoot + 'Create',
read: urlRoot + 'Read',
update: urlRoot + 'Update',
destroy: urlRoot + 'Destroy'
},
reader: {
type: 'json',
metaProperty: 'meta',
rootProperty: 'data',
idProperty: 'id',
totalProperty: 'meta.total',
successProperty: 'meta.success'
},
writer: {
type: 'json',
encode: true,
writeAllFields: true,
rootProperty: 'data',
allowSingle: false
}
}
});
答案 0 :(得分:0)
您需要使用this.getStore().isLoad()
来检查存储是否已加载。如果this.getStore.load()
将重新加载商店。如果它是异步加载,则您的查找将失败,因为在执行时存储可能尚未加载。
...
{
xtype: 'gridcolumn',
text: 'Contragents',
dataIndex: 'contragent',
editor: {
xtype: 'combobox',
allowBlank: false,
displayField: 'name',
valueField: 'id',
queryMode: 'remote',
store: Ext.data.StoreManager.lookup('ContrAgents')
},
renderer: function(value, metaData, record, rowIndex, colIndex, store, view){
if(this.getStore().isLoaded()){
store_ca = Ext.data.StoreManager.get('ContrAgents');
//'ContrAgents' should be 'storeId' for the store
// you are refering to and should be listed in
//stores[] array of app.js
index_record = store_ca.findExact('id', 1);
}
if(index_record != -1){
rs = store_ca.getAt(index_record).data;
return rs.name;
}
}
},
...