PDA

View Full Version : pointer this. Call method of instance



amt779
4 Aug 2010, 1:37 PM
here is the class I made


menuTreePanelUi = Ext.extend(Ext.tree.TreePanel, {
rootVisible: false,
enableDD: true,
title: 'My Tree',
initComponent: function() {
this.root = {
text: 'manutreenode'
};
this.loader = {
dataUrl : url_menutree
,baseAttrs : {
listeners: {
dblclick: function(node) {
var cs = this;
cs.table = 'page';
if( 1 < node.getDepth() ){
if(null == tabs.getItem(cs.table+cs.id))
tabs.add( new tabPageFormUi({
id : cs.table + cs.id
,table : cs.table
,tableid : cs.id
,title : cs.text
,url : url_qprocessor
,method : 'POST'
}) ).show();
else tabs.setActiveTab(cs.table+cs.id);
}
}
}
}
};
this.tbar = {
xtype: 'toolbar',
items: [
{
text: 'N',
iconCls: 'additem-ico',
handler: function(){
var name = prompt('??????? ???????? ?????? ?????? ???? ?????', '');
if(null != name && "" != name){
Ext.Ajax.request({
url: url_qprocessor,
params : { table : 'navi', name: name, parent: '1', act : 'add' },
timeout: 300,
method: 'POST',
success: function(xhr) {
this.getLoader().load(this.getRootNode());
this.getRootNode().expand();
},
failure: function(xhr) {
alert('????? ??? ????????? ??????. "' + xhr.responseText + '"');
}
});
}
}
}
]
}
menuTreePanelUi.superclass.initComponent.call(this);
}
});



my trouble with


this.getLoader().load(this.getRootNode());
this.getRootNode().expand();

I want somehow to call for methods of the current instance of menuTreePanelUi class. But dont know how to do it properly. Please help

Condor
4 Aug 2010, 11:49 PM
You also need to specify the scope for the success and failure methods.

amt779
5 Aug 2010, 12:23 AM
could you give some sample code how can i make it work?

Condor
5 Aug 2010, 12:27 AM
this.tbar = {
xtype: 'toolbar',
items: [{
text: 'N',
iconCls: 'additem-ico',
scope: this, // <- call handler with this == current instance
handler: function () {
var name = prompt('??????? ???????? ?????? ?????? ???? ?????', '');
if (null != name && "" != name) {
Ext.Ajax.request({
url: url_qprocessor,
params: {
table: 'navi',
name: name,
parent: '1',
act: 'add'
},
timeout: 300,
method: 'POST',
scope: this, // call success/failure with this == handler.this == current instance
success: function (xhr) {
this.getLoader().load(this.getRootNode());
this.getRootNode().expand();
},
failure: function (xhr) {
alert('????? ??? ????????? ??????. "' + xhr.responseText + '"');
}
});
}
}
}]
}

amt779
5 Aug 2010, 3:30 AM
oh! Thank you very much. now I get it ))