[英]Cannot populate fields from Ext.data.store
這是我的模型:
Ext.define('Email', {
extend: 'Ext.data.Model',
idProperty: 'emailid',
fields: [
{ name: 'emailid', type: 'int' },
{ name: 'emailsubject', type: 'string', useNull: true },
{ name: 'emailbody', type: 'string', useNull: true },
{ name: 'emailto', type: 'string', useNull: true },
{ name: 'emailfrom', type: 'string', useNull: true },
]
});
和數據存儲區:
var EmailDataStore = {
getDetailStore: function(aid) {
var options = {
autoLoad: true,
autoSync: true,
pageSize: 1,
remoteFilter: true,
remoteGroup: true,
remoteSort: true,
model: 'Email',
proxy: {
type: 'ajax',
url: 'datastores/datastore-email.asp?action=details&auditid=' + aid,
reader: {
type: 'json',
root: 'emailDetails'
}
}
};
if (typeof (options2) != 'undefined') {
options = Ext.merge(options, options2);
}
var detailStore = Ext.create('Ext.data.Store', options);
return detailStore;
}
}
我不會包括ASP,因為JSON會正確返回數據。 但是在接下來的代碼中,
...
PortalEmailGrid.prototype.detailStore = null;
PortalEmailGrid.prototype.showEmailDetails = function (id) {
var self = this;
//alert(id);
self.detailStore = EmailDataStore.getDetailStore(id);
//view store at this state - object appears to exist with the returned record in it
console.log(self.detailStore);
var firstItem = self.detailStore.first();
//undefined here
console.log(firstItem);
//count is zero, but i can see the object in the console log above
alert('detailStore count: ' + self.detailStore.count());
var win = Ext.create('Ext.window.Window', {
title: 'Email Details',
store: self.detailStore,
height: 400,
width: 800,
bodyPadding: 4,
items: [
{
xtype: 'textfield',
name: 'tofield',
dataIndex: 'emailto',
fieldLabel: 'To'
},
{
xtype: 'textfield',
name: 'subjectfield',
dataIndex: 'emailsubject',
fieldLabel: 'Subject'
}
]
});
win.show();
}
我無法獲取要使用detailStore
數據填充的字段。 但是,當我在Firebug中登錄self.detailStore
,可以看到該對象及其詳細信息。 self.detailStore.count()
顯示為零,但是根據控制台,數據應該在該位置。 我懷疑由於這種差異,沒有使用dataIndex
信息填充字段。 之前的代碼塊也被調用:
var selected = self.grid.selModel.selected;
var id = selected.items[0].raw.emailid;
//var status = selected.items[0].raw.status;
PortalEmailGrid.prototype.showEmailDetails(id);
您能看到沒有從數據存儲中加載數據的任何原因嗎?
商店加載是異步的,當您將計數記錄到控制台時,商店尚未加載。 Firebug始終顯示對象的“最新”狀態,這就是為什么您可以看到數據的原因。 您需要在商店上監聽load事件。
因此,如果刪除autoLoad配置,則可以執行以下操作:
self.detailStore = EmailDataStore.getDetailStore(id);
self.detailStore.load({
callback: function(){
console.log('loaded, do something');
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.