-
12 Oct 2011 11:01 AM #1
Answered: How to extend a Ext.data.Store with constructor
Answered: How to extend a Ext.data.Store with constructor
Hi,
I'm trying to subclass the Ext.data.Store as follows:
and then use it as:Code:Ext.define('SPVStore', { extend: 'Ext.data.Store', proxy : { type : 'ajax', url : '.im.read', extraParams:[{type:'SourcePropertyValue', source_propertytype_id: 1}], reader : { type : 'json', root : 'item' } }, model:'SourcePropertyValue', initComponent : function() { alert(3); } });
but when call edit.store.load() I get no return values (server is not hit) and no error, and also the alert(3) (in the subclass Constructor) is not being called. I have a feeling there may be a few things wrong with how I'm doing this and I'd really appreciate some guidance.Code:edit = new Ext.form.ComboBox({ store: new SPVStore(), displayField:'value_desc', ...
Thanks,
-
Best Answer Posted by skirtle
It is not correct to call initComponent the constructor, they are two different things. initComponent is a template method provided for initializing a component. It is called by the actual constructor and is never passed any arguments. The constructor will copy all of the properties in the config object onto this and initComponent is expected to get all the information it needs by reading the properties on this.
Further, initComponent only exists for components. A store is not a component. You would need to override constructor instead.
Adding a property foo to this won't result in it being in your extraParams. At the point you're defining the extraParams the value of this is probably the global window object, so that parameter will just be undefined (hence what you're seeing at your server). What you've got at the moment is equivalent to the following:
Clearly this will not be the instance of SPVStore.Code:var param = this.foo; Ext.define('SPVStore', { ... proxy : { ... extraParams: {..., source_propertytype_id: param}, ... }, ... });
There are several ways to achieve a result similar to the one you're looking for. Here's one:
Note I haven't actually tested this code, it may need a little tweaking.Code:Ext.define('SPVStore', { extend: 'Ext.data.Store', model: 'SourcePropertyValue', proxy : { type : 'ajax', url : '.im.read?', reader : { root : 'item', type : 'json' } }, constructor: function() { this.callParent(arguments); this.getProxy().extraParams = { source_propertytype_id: this.foo, type: 'SourcePropertyValue' }; } }); ... new SPVStore({foo: 4});
-
12 Oct 2011 1:20 PM #2
ok so I have figured out why the records weren't returning.
so the only question I have now is how to define a constructor on my Ext.data.Store subclass, and call that constructor with an argument?
-
12 Oct 2011 1:25 PM #3
this might clarify what I'm trying to do, but doesn't work; i.e the value "" is being sent back to the server for 'foo' instead of 4:
Code:Ext.define('SPVStore', { extend: 'Ext.data.Store', proxy : { type : 'ajax', url : '.im.read?', extraParams:{type:'SourcePropertyValue',source_propertytype_id: this.foo}, reader : { type : 'json', root : 'item' } }, model:'SourcePropertyValue', initComponent : function(foo) { this.foo = foo; } });Code:edit = new Ext.form.ComboBox({ store: new SPVStore(4),
-
12 Oct 2011 7:41 PM #4
It is not correct to call initComponent the constructor, they are two different things. initComponent is a template method provided for initializing a component. It is called by the actual constructor and is never passed any arguments. The constructor will copy all of the properties in the config object onto this and initComponent is expected to get all the information it needs by reading the properties on this.
Further, initComponent only exists for components. A store is not a component. You would need to override constructor instead.
Adding a property foo to this won't result in it being in your extraParams. At the point you're defining the extraParams the value of this is probably the global window object, so that parameter will just be undefined (hence what you're seeing at your server). What you've got at the moment is equivalent to the following:
Clearly this will not be the instance of SPVStore.Code:var param = this.foo; Ext.define('SPVStore', { ... proxy : { ... extraParams: {..., source_propertytype_id: param}, ... }, ... });
There are several ways to achieve a result similar to the one you're looking for. Here's one:
Note I haven't actually tested this code, it may need a little tweaking.Code:Ext.define('SPVStore', { extend: 'Ext.data.Store', model: 'SourcePropertyValue', proxy : { type : 'ajax', url : '.im.read?', reader : { root : 'item', type : 'json' } }, constructor: function() { this.callParent(arguments); this.getProxy().extraParams = { source_propertytype_id: this.foo, type: 'SourcePropertyValue' }; } }); ... new SPVStore({foo: 4});


Reply With Quote