[jQuery] Binding functions referenced by an array
Hello
I'm having some troubles regarding binding functions referenced by an
Array:
I have this piece of code
function f1() {
alert("dklfsd");
}
function Dialog(title) {
this._dlg_btns_fns = new Array("f1");
}
Dialogo.prototype.setButtons = function (val) {
var tp = valor.split("@");
for(i=0;i<tp.length;i++) {
tb = tp[i].split("|");
this._dlg_btns.push(tb[0]);
this._dlg_btns_fns.push(tb[1]);
}
}
//assuming that we call setButtons like this : dialog.setButtons("OK|
f1@CANCEL|f2");
//on the init function I have something like this in the init function
of the Dialog object:
html ='<div id="overlay_botoes">';
html +='<table border="0" cellspacing="0" cellpadding="0">';
for(i=0; i<this._dlg_btns.length;i++) {
html += '<td><a class="botao" href="'+this._dlg_btns_fns[i]
+'">'+this._dlg_btns[i]+'</a></td>';
html += '<td> </td>';
}
html += '</table>';
html += '</div>';
$("body").append(html);
var links = $("#overlay_botoes a");
links.click(function(e) {
e.preventDefault();
var indexOfThisLink = links.index(this);
var tb = $("#overlay_botoes a").get(indexOfThisLink).toString();
eval(tb.replace(location.href,""));
});
I want to assign the contents of the this._dlg_btns_fns as functions
but I can't reference the this._dlg_btns_fns from the object. I've
read something on the groups like caching the variable but can't seem
to apply in this piece of code.
Thank you for any help you can provide on this.