store.loadData是否在ExtJs 4.2.5上的商店上触发load事件?

时间:2016-03-09 17:29:50

标签: javascript extjs extjs4

store.loadData是否在ExtJs 4.2.5上的商店上触发加载事件?

文档说明了:http://docs-devel.sencha.com/extjs/4.2.5/#!/api/Ext.data.Store-method-loadData

但鉴于我所经历的事情,它看起来并不像它,并且还在查看源代码:

loadData: function(data, append) {
    var length = data.length,
        newData = [],
        i;

    //make sure each data element is an Ext.data.Model instance
    for (i = 0; i < length; i++) {
        newData.push(this.createModel(data[i]));
    }

    this.loadRecords(newData, append ? this.addRecordsOptions : undefined);
},

好的,所以loadRecords可能会解雇它吗?

loadRecords: function(records, options) {
    var me     = this,
        i      = 0,
        length = records.length,
        start,
        addRecords,
        snapshot = me.snapshot;

    if (options) {
        start = options.start;
        addRecords = options.addRecords;
    }

    if (!addRecords) {
        delete me.snapshot;
        me.clearData(true);
    } else if (snapshot) {
        snapshot.addAll(records);
    }

    me.data.addAll(records);

    if (start !== undefined) {
        for (; i < length; i++) {
            records[i].index = start + i;
            records[i].join(me);
        }
    } else {
        for (; i < length; i++) {
            records[i].join(me);
        }
    }

    /*
     * this rather inelegant suspension and resumption of events is required because both the filter and sort functions
     * fire an additional datachanged event, which is not wanted. Ideally we would do this a different way. The first
     * datachanged event is fired by the call to this.add, above.
     */
    me.suspendEvents();

    if (me.filterOnLoad && !me.remoteFilter) {
        me.filter();
    }

    if (me.sortOnLoad && !me.remoteSort) {
        me.sort();
    }

    me.resumeEvents();
    if (me.isGrouped()) {
        me.constructGroups();
    }
    me.fireEvent('datachanged', me);
    me.fireEvent('refresh', me);
},

它也没有被解雇。

这是一个已知问题还是我错过了什么?

2 个答案:

答案 0 :(得分:3)

loadData不会触发load事件,因为只要商店从远程数据源({{3})读取数据,load事件就会触发})。 loadData适用于第一个参数中提供的本地数据。

您发现文档中存在不准确之处。我在版本4.1.1中跟踪了您的研究,但我找不到loadData在那里触发load事件。

但是loadRawData用于触发4.1.1中的load事件,但它在4.2.5中不再存在。在docs中,您可以阅读:

从4.2开始,此(loadRawData)方法将不再触发{@link#event-load}事件。

答案 1 :(得分:0)

相反,你可以依靠刷新活动,看看这个我创建的示例,其中展示了用法

Refresh