On Mon, Mar 8, 2010 at 02:26, Qoodary <[email protected]> wrote:

>
> Hi Derrell, Hi list,
> thank you very much for your help,
>
> I tried to add the the third parameter "this" to the addListener function.
>
> form.addListener('completed',function(e) {
>         this.debug('completed');
>        file.setFieldValue('');
>        var response = this.getIframeHtmlContent();
>        this.debug(response);
>        ////////////////////////////////////////////////////////////////
>                this.getTableData();
>        ///////////////////////////////////////////////////////////////////
>        wm1.close();
> }, this);
>
> But now I get the error message;
> this.getIframeHtmlContent is not a function
>
> I do not know how to change the code that both function will work?
>

Ah, sorry, I hadn't noticed that you were also accessing methods of the
form.

You have a couple of choices:

Choice 1.

In addition to assigning the form instance to a local variable as you're
doing here:

  var form = new firstQxApp.UploadForm('uploadFrm','/uploads/upload.php');

assign it to a member variable of your application object as well:

  var form = this.setUserData("form", form) = new
firstQxApp.UploadForm('uploadFrm','/uploads/upload.php');

Then, in your listener handler you can use:

  var response = this.getUserData("form").getIframeHtmlContent();

Choice 2.

JavaScript has a concept of "closures" which allow a variable defined in one
scope to retain its value in another scope even if the first scope goes
away. If you're not familiar with closures, it's worth reading up on, as
it's a powerful feature (and one that can be easily misused and cause memory
leaks if used improperly).

In this case, since the 'form' variable is active at the time that you
define your listener, i.e. it references a firstQxApp.UploadForm object, you
can reference that variable inside of your handler. Even if the outer scope
in which the 'form' variable is used were to go away (which it doesn't, in
your application), the use inside of your handler would retain its value.
You can therefore simply change

  this.getIframeHtmlContent()

to

  form.getIframeHtmloContent()

and that 'form' object will be the one initialized prior to creation of your
handler. This is the easiest solution, and a perfectly valid one, but if
you're going to use closures, it's really worth reading up on them to know
their pit-falls.

Cheers,

Derrell
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to