LoginSignup
0
0

More than 1 year has passed since last update.

ExtJS6系、7系でExtJS3系のReader定義を使う

Last updated at Posted at 2020-03-18

ExtJS 3.4 で使っていた Ext.data.Record の定義を ExtJS 6, 7 でそのまま使いたいとき。
もしくは横着したい人向け。

Ext.override(Ext.data.XmlReader, {
	constructor: function(config) {
		if(!config.model && config.fields) {
			config.model = 'Model-' + Ext.id();
			Ext.define(config.model, {
				extend: 'Ext.data.Model',
				fields: config.fields
			});
		}

		Ext.data.XmlReader.superclass.constructor.apply(this, arguments);
	}
});

Overrideした後は、XmlReader 使うときにこんな感じで定義する。

new Ext.data.XmlReader({
	record: 'data',
	rootProperty: 'data',
	fields: [
		{ name: 'RESULT' },
		{ name: 'ID' }
	]
});

モデル定義が無意味になるという点においては、負荷軽減とかコーディングコストとかその辺りからみると全く無意味なので、その辺も要注意。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0