On 6/20/07, TiNo [EMAIL PROTECTED] wrote:
With the following code (shortend):
--
var EditGrid = function (base_url, target_id) {
bindMethods(this);
this.base_url = base_url;
this.target_id = target_id;
this.editing = false;
this.direction = 6; //forward, see your numpad
this.editcell = null;
this.render();
}
EditGrid.prototype = {
render : function(params) {
params = params || {};
params = eval(params);
params['tg_random'] = new Date().getTime();
params['tg_format'] = json;
var d = loadJSONDoc(this.base_url + '/get_data', params);
d.addCallback(this.createGrid);
return d;
},
createGrid : function(response) {
var grid = Widget.editgrid.render(this.target_id, response);
swapDOM(this.target_id, grid);
connect(window,'onkeydown',this.handleKey);
},
editCell : function(e) {
[...]
},
handleKey : function(e) {
[...]
if(e.key()['string'] == 'KEY_ESCAPE')
{
this.abort()
e.stop()
}
[...]
},
abort : function(e){
var editcell = this.editcell;
if(!this.editing) return;
swapDOM(editcell.firstChild,document.createTextNode(this.original));
this.editing = false;
this.original = null;
this.editcell = null;
if(e)e.stop();
}
[etc...]
}
-
I have the following problem: the 'this' variable is overwritten by
the EditGrid function every time one of its methods is called.
Example: editCell is called on onclick on a tablecell, it thereby sets
this.editcell to the target cell, and this.editing to true. But when
the handleKey method is called by a onkeydown, this.editing is set to
false, and this.editcell to null, like the values they had initially.
What am I doing wrong?
There was a bug in connect that interfered with bind(). You can either
upgrade to the latest svn trunk, or change this:
connect(window,'onkeydown',this.handleKey);
to this:
connect(window,'onkeydown',this, 'handleKey');
-bob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---