PDA

View Full Version : Lost in Ext.extend ... where am I ...?



Dill0r
5 Feb 2011, 2:15 PM
Hello,

Im new to Sencha Touch.
First of all ive to say that this is amazing work. thank you!

im a little lost in Ext.extend.

i just want to build a class that contains of a simple text-label, a toggle and a slider.
i want to add event listeners to the controls.
but i cant figure out how to access them to add listeners and so on.
pls see comments in the code below....

thanks for any help...




MyClass = Ext.extend(Ext.Container, {
constructor: function(cparam){
var foo1 = "FOO 1"

//id like to access the item from here, but this.down does not work...
//how can i access the child-items from the construcotr?
//TypeError: Cannot call method 'slice' of undefined
//console.log(this.down("#myItem"));

//this metod cant be called from here. after instantiation its possible...
//TypeError: Cannot call method 'slice' of undefined
//this.access_item();
MyClass.superclass.constructor.call(this);
},
itemId : "myclass_id",
foo2 : "FOO 2",
access_item : function(){
console.log(this.down('#myItem').foo3);
},
my_listener : function(){
console.log(this.up("#myclass_id").foo2)
},
items :[
{
itemId : "myItem",
xtype : "togglefield",
'foo3' : "FOO 3",

//id like to access the field in the main-class, but here the context is DOMWindow, so its not possible ...?
//TypeError: Object [object DOMWindow] has no method 'up'
//'foo4' :this.up("#myclass_id").foo2


listeners: {
change: {
fn:function(){
// THIS WORKS...!?
console.log(this.up("#myclass_id").foo2)
}
}
},
/*
Uncaught TypeError: Object [object DOMWindow] has no method 'up'
listeners: {
change: {
fn:this.up("#myclass_id").my_listener
}
},*/
}
]
}
)

m = new MyClass();

//THIS WORKS
m.access_item();




ive also tried to create "real" objects... but fail also:


MyClass2 = Ext.extend(Ext.Container, {
constructor: function(cparam){
var tog = new Ext.form.Toggle();
console.log(tog);
this.add(tog);
var l = function(e){console.log(e)};
tog.on(change, this.l);
MyClass.superclass.constructor.call(this);

},
}
)