简体   繁体   English

无法填充Ext.data.store中的字段

[英]Cannot populate fields from Ext.data.store

Here is my model: 这是我的模型:

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 },
    ]
});

and DataStore: 和数据存储区:

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

I won't include the ASP because the JSON is returning the data appropriately. 我不会包括ASP,因为JSON会正确返回数据。 But in this next bit of code, 但是在接下来的代码中,

...
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();
}

I cannot get the fields to populate with the detailStore 's data. 我无法获取要使用detailStore数据填充的字段。 But when I log self.detailStore , in Firebug, I can see the object and its details. 但是,当我在Firebug中登录self.detailStore ,可以看到该对象及其详细信息。 self.detailStore.count() shows zero, but according to the console, the data should be there. self.detailStore.count()显示为零,但是根据控制台,数据应该在该位置。 I suspect because of this discrepancy, the fields are not being populated with the dataIndex information. 我怀疑由于这种差异,没有使用dataIndex信息填充字段。 Also the previous code block was called by: 之前的代码块也被调用:

var selected = self.grid.selModel.selected;
var id = selected.items[0].raw.emailid;
//var status = selected.items[0].raw.status;
PortalEmailGrid.prototype.showEmailDetails(id);

Can you see any reason why the data isn't loading from the datastore? 您能看到没有从数据存储中加载数据的任何原因吗?

Store loading is asynchronous, by the time you're logging the count to the console, the store is yet to be loaded. 商店加载是异步的,当您将计数记录到控制台时,商店尚未加载。 Firebug always shows the "up to date" status of the object, which is why you can see the data. Firebug始终显示对象的“最新”状态,这就是为什么您可以看到数据的原因。 You need to listen to the load event on the store. 您需要在商店上监听load事件。

So if you remove the autoLoad config, you can do something like this: 因此,如果删除autoLoad配置,则可以执行以下操作:

self.detailStore = EmailDataStore.getDetailStore(id);
self.detailStore.load({
    callback: function(){
        console.log('loaded, do something');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM