0

这是我的模型:

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);

您能看出数据未从数据存储区加载的任何原因吗?

4

1 回答 1

1

存储加载是异步的,当您将计数记录到控制台时,存储尚未加载。Firebug 始终显示对象的“最新”状态,这就是您可以看到数据的原因。你需要监听 store 上的 load 事件。

因此,如果您删除 autoLoad 配置,您可以执行以下操作:

self.detailStore = EmailDataStore.getDetailStore(id);
self.detailStore.load({
    callback: function(){
        console.log('loaded, do something');
    }
});
于 2013-02-13T21:09:59.790 回答