Problema con button handler
Por qué en este pedazo de codigo que os voy a poner , el boton "Gestión usuarios" cuando hago click en el me da este error ???
this.cargar_contenido is not a function
os pongo el codigo a ver si me ayudais con el error y gracias <!-- s;) --><!-- s;) -->
Ext.ns('gestorweb');
gestorweb.aplicacion = {
coleccion:new Ext.util.MixedCollection(),
init: function(){
Ext.QuickTips.init();
this.panelmenu = new Ext.Panel({
height:0,
tbar: [{
text: 'Salir',
iconCls: 'session_close',
handler:function(){
Ext.Ajax.request({
url: "<?php echo(site_url('ruta'));?>",
method:"POST",
success:function(){
document.location.href="<?php echo(site_url('ruta'));?>";
}
});
}
}, '-', {
text:'Gestión usuarios',
iconCls:'user_manager',
scope:this,
handler: this.cargar_contenido('ges_users')
}]
});
this.panelmenus = new Ext.Panel({
title: "Gestor web",
region: "north",
height: 54,
tbar: panelmenu
});
this.panelcontenidos = new Ext.Panel({
title: "Contenidos" ,
id:"contenidos",
frame:false,
layout:'fit'
});
this.general = new Ext.Viewport({
layout: 'border',
loadMask: true,
id: 'layout-browser',
items: [panelmenus, {
title: "Detalles",
id: "detalles-panel",
region: 'west',
collapsible: true,
width: 200,
minSize: 100,
maxSize: 350,
margins: '0 0 0 0',
cmargins: '0 0 0 0',
bodyStyle: 'padding:5px;',
split: true
}, {
region: 'center',
id:'regioncentro',
autoscroll: true,
margins: '0 0 0 0',
cmargins: '0 0 0 0',
layout:'anchor',
items: [panelcontenidos]
}]
});
},
cargar_contenido:function(){
console.debug('dentro');
if (typeof(this.coleccion.get(arguments[0]))=="undefined"){
if (typeof(arguments[1])!="undefined") {
this.cargar_js_css.load(arguments[1]);
}
Ext.get("oculto").load({
url: '<?php echo(site_url("admin"));?>/' + arguments[0],
scripts:true
});
}
else{
switch(this.coleccion.item(arguments[0]).getXType()){
case 'window':
this.coleccion.item(arguments[0]).show();
break;
}
}
},
cargar_js_css:function(){
var loadComponent=function(component,name, callback){
var fileType = component.substring(component.lastIndexOf('.'));
var head = document.getElementsByTagName("head")[0];
var done = false;
if (fileType === ".js") {
fileRef=Ext.getBody().createChild({
tag: 'script',
type: 'text/javascript',
src: "<?php echo(base_url());?>ext/ux/" + component // The url!
}, null, true);
fileRef.onload = fileRef.onreadystatechange = function(){
if (!done) {
done = true;
if(typeof callback == "function"){
callback();
};
//head.removeChild(fileRef);
}
};
} else if (fileType === ".css") {
fileRef=Ext.getBody().createChild({
tag: 'link',
rel:'stylesheet',
type: 'text/css',
src: "<?php echo(base_url());?>ext/ux/" + component // The url!
}, null, true);
}
if (typeof fileRef != "undefined") {
head.appendChild(fileRef);
gestorweb.aplicacion.coleccion.add(name,fileRef)
}
};
return{
load:function(components,callback){
Ext.each(components, function(component){
var fileName=component.substr(0,component.lastIndexOf('.'));
var el=typeof(gestorweb.aplicacion.coleccion.get(fileName));
if (el.toString()=="undefined") {
loadComponent(component, fileName,callback);
}
});
}
};
}()
}
Ext.onReady(gestorweb.aplicacion.init,gestorweb.aplicacion);
Holass, he probado tu código, te marca error por que en el handler correcto sería:
handler: this.cargar_contenido, sin parametros, Si colocas parametros, estas invocando a esa función y el API dice que debes colocar la Función a ser llamada, no llamar a una función. Ahora si quieres pasar parametros podrías utilizar el createDelegate(ver el api de Function), y quedaría así:
handler: this.cargar_contenido.createDelegate(this,['ges_users'])..tambien marca error ya que en una parte de tu codigo utilizas [color=#404040]this.panelmenus [/color] y mas abajo utilizas [color=#404040]panelmenus [/color](sin this.), lo correcto es que si estas trabajando con this.panelmenus tambien abajo utilices this.panelmenus, lo mismo ocurre con tu [color=#804040]this.panelcontenidos[/color] Puedes hecharle un vistazo a acerca de este tema en quizzpot: [url]http://www.quizzpot.com/2009/03/el-contexto-y-la-variable-this/[/url] saludos
¿Conoces a alguien que pueda responder esta pregunta? Comparte el link en Twitter o Facebook
Es necesario registrarse para poder participar en el foro! Si ya tienes una cuenta puedes entrar y comentar en este foro.
