PDA

View Full Version : Combobox works when I move my store



UbuntuPenguin
13 Aug 2012, 4:54 PM
Hello Everyone,
I had a custom combobox class that used a store. I declared my store like so



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', {


This worked fine until I had another instance declared in another view by xtype.

I was confounded for days wondering how my code broke overnight. Then I changed my combobox and moved my store into the initComponent declaration.



...
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, {
...



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.

evant
13 Aug 2012, 5:03 PM
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:



Ext.define('Foo', {
bar: []
});

var a = new Foo();
a.bar.push(1);
var b = new Foo();
console.log(b.bar[0]);

UbuntuPenguin
13 Aug 2012, 5:29 PM
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 ?