Extjs4 Store 확장,'aftersync'이벤트 추가

1632 단어 extjs4

/**
 * Store 
 */
Ext.define('Ext.ux.StoreEx', {
	extend : 'Ext.data.Store',
	alias : 'store.storeex',

	batchUpdateMode : 'complete',

	constructor : function(config) {
		var me = this;

		me.addEvents('aftersync');

		me.callParent([ config ]);
	},

	onBatchComplete : function(batch, operation) {
		var me = this, operations = batch.operations;
		var length = operations.length, i;

		me.suspendEvents();

		for (i = 0; i < length; i++) {
			me.onProxyWrite(operations[i]);
		}

		me.resumeEvents();

		me.fireEvent('aftersync', me);
		me.fireEvent('datachanged', me);
	},

	sync : function() {
		var me = this;
		var options = {};
		var toCreate = me.getNewRecords();
		var toUpdate = me.getUpdatedRecords();
		var toDestroy = me.getRemovedRecords();
		var needsSync = false;

		if (toCreate.length > 0) {
			options.create = toCreate;
			needsSync = true;
		}

		if (toUpdate.length > 0) {
			options.update = toUpdate;
			needsSync = true;
		}

		if (toDestroy.length > 0) {
			options.destroy = toDestroy;
			needsSync = true;
		}

		if (needsSync && me.fireEvent('beforesync', options) !== false) {
			me.proxy.batch(options, me.getBatchListeners());
		}

		return needsSync;
	}
});

좋은 웹페이지 즐겨찾기