PDA

View Full Version : [3.3.0] Ext.decode vs direct eval call



danellison
11 May 2011, 10:14 AM
Hi all. Viewport does an Ext.direct call to php backend for menu contents and handler methods are returned as json text.


if(COI.userProfile.showribbon != "off") {
function loadRibbon(json, e){
if(e.status){
Ext.apply(this, Ext.util.JSON.decode(json.data.methods));
ribbonBar = new Ext.ux.Ribbon({
items: Ext.util.JSON.decode(json.data.items),
});
this.COI_NorthPanel.getTopToolbar().add(ribbonBar);
this.doLayout();
}
}
COI.modmgr.loadRibbonMenu(COI.userProfile, loadRibbon, this);
}


The above code loads the menu and presents correctly. However, my applied methods are not available to my menu handler routines. Reports that the handler is not a function.

Change to


if(COI.userProfile.showribbon != "off") {
function loadRibbon(json, e){
if(e.status){
eval("Ext.apply(this, "+json.data.methods+");");
eval("this.ribbonBar = new Ext.ux.Ribbon({ items : "+json.data.items+"});");
this.COI_NorthPanel.getTopToolbar().add(this.ribbonBar);
this.doLayout();
}
}
COI.modmgr.loadRibbonMenu(COI.userProfile, loadRibbon, this);
}


And everything works fine. I can reference "this" in my remote methods and handlers. Why is Ext losing scope on the Ext.decode method call? I tried Ext.decode.call(this, json.data.methods) with no change. Since extjs ultimately performs an eval in the decode method I don't understand why there is a disparity between the two versions. Anybody shed any light on this for me? I appreciate your time, I don't know why I would rather let extjs do an "eval" than do it myself :D

Have a great day!
Dan