Adam Steffen wrote:
I'm not experienced with javascript at all so bear with me. I'm trying to make a Web Interface with many buttons, check boxes, selection lists, etc. and associate with these widgets a set of data. So that changing the selections on the interface update the data set.

Using qooxdoo, I made a class to hold the data, and added member functions that will update the data set, based on passed variables. I then created an interface window with all the widgets. What I want to do is associate the member functions of the data set with listeners of the corresponding widgets. My simple brain would like to do the following:

In window interface class:
/ ...
mycheckboxgroup.addListener("changeSelection", myDataSet.updateFunction(data_name,mycheckboxgroup), myDataSet);
 .../

Then in data set class:
/ ...
    updateFunction : function(data_name,checkbox)
    {
        value = checkbox.getSelected().getValue();
        this.setData(data_name,value);
     }
 .../

This implimentation just executes the updateFunction once as the listener is added. Based on what I've read, this is because the function argument should be a pointer to a function rather than a function() call.

Right, the second argument has to evaluate to a function object, to be precise.

  But then how do you pass arguments to the Listener as it is constructed?

You don't. The listener function is monadic, taking an event object instance as a single argument. This is the listener protocol you have to adhere to. You say something like ...addListener("event", function (e) { var d = e.getData(); ....}, obj);

e will be provided at run time and is all you get for the listener invocation. The type of e can vary according to the class and event you're registering with, so check the API for that.


Is there a way to create a generic listener function that takes variable arguments? I don't want to have to write the code for each new listener function for each of the 50 checkboxgroups i have, but I want to add a listner to each and associate that listener to a data set based on a variable.

You can write a listener factory like

   function makeListener (specialArg) {
          return function (e) { /* use event e and specialArg here */ };
   }

and then call it when you add a listener

   ...addListener("event", makeListener(specialArg), obj);

HTH,

T.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to