-
13 Aug 2012 4:54 PM #1
Answered: Combobox works when I move my store
Answered: Combobox works when I move my store
Hello Everyone,
I had a custom combobox class that used a store. I declared my store like so
This worked fine until I had another instance declared in another view by xtype.Code:ds = Ext.create('Ext.data.Store', { model: 'KesslerAdmin.model.LineItemType', proxy: { type:'ajax', url:'line_item_type/search_by_product_type.json', reader:{ type:'json' } } }); Ext.define('KesslerAdmin.view.AwesomeCombobox', {
I was confounded for days wondering how my code broke overnight. Then I changed my combobox and moved my store into the initComponent declaration.
After that my combobox which was declared twice by xtype in my application worked like a charm. My question is, what concept am I missing. Why would declaring a component by its xtype break the combobox. By the way, if I remember correctly, the error was 'Object <object> has no method read.Code:... initComponent:function () { var me = this; var ds = Ext.create('Ext.data.Store', { model: 'KesslerAdmin.model.LineItemType', proxy: { type:'ajax', url:'line_item_type/search_by_product_type.json', reader:{ type:'json' } } }); me.store = ds, Ext.applyIf(me, { ...
-
Best Answer Posted by evant
When you put it in the definition, it gets shared across instances. For "primitive" types (strings, numbers, bools) it isn't a problem, however for objects it becomes apparent:
Code:Ext.define('Foo', { bar: [] }); var a = new Foo(); a.bar.push(1); var b = new Foo(); console.log(b.bar[0]);
-
13 Aug 2012 5:03 PM #2Sencha - Ext JS Dev Team
- Join Date
- Apr 2007
- Location
- Sydney, Australia
- Posts
- 15,103
- Vote Rating
- 97
- Answers
- 171
When you put it in the definition, it gets shared across instances. For "primitive" types (strings, numbers, bools) it isn't a problem, however for objects it becomes apparent:
Code:Ext.define('Foo', { bar: [] }); var a = new Foo(); a.bar.push(1); var b = new Foo(); console.log(b.bar[0]);Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
13 Aug 2012 5:29 PM #3
Thanks Evan. Just one more question, do you know why having the 'store' shared across instances would cause the 'Object <object> has no read method' error ?


Reply With Quote