issue calling handler function with a parameter - function

I am using sencha touch. Can i call parametrized handler function on an item of action sheet ? If yes then how to do this. Kindly help me ..
I want to do this ,,
var z = function test(){alert('Hellow')};
In the handler function :
handler:function(z){
alert(z);
}
it is not working .. Just showing .. "Index.html (Object:Object)"
Thanx in advance

Yes, you can do this but this is based on the parameters provided by the caller of the handler. In case of it button this would be the 'click' event. But you can always view all passed arguments when reading the arguments array like
handler:function(){
console.log(arguments);
}
and if you know that there is for example one argument you know you (lets take the button) can define it
handler:function(btn){
btn.disable();
}
You also need to know that alert is not capable of printing JavaScript Objects! Use console.log for this.

Related

How to pass a function AND its parameters into another function

My use case is this: a function called 'time' that will return how long it takes to run any function you give it.
So the time function needs to know all the parameters to pass into the function when it calls it.
I know how to pass a function into another function, but how can I pass all its parameters, without knowing in advance how many and what type they are, so they can be used when calling the function?
For example, if I pass in an array of all the parameters I need to send, is there some Dart way to call a function by expanding an array into a list of parameters? Or perhaps there's another way to capture and pass a function call, including all parameters, as one executable object?
I'm also interested in knowing if there's a more Dartful way to accomplish what I'm trying to do re: timing function calls.
I believe using a List of parameters with the apply method is the most common way and practical of doing this and I have seen something similar used to pass parameters for JS interop. As far as I know, there isn't a way to expand an array into a list of parameters like you can for javascript. You could of course create your own object to pass arguments, but I think it would add unnecessary complexity and end up being more difficult.
Example of passing parameters to function in dart:js here.

Polymer function call with parameters

This seems like a very simple one, but somehow I am not sure how to do it.
I want to send data to a Polymer component with the "core-collapse-open" event but this is not working:
<core-collapse on-core-collapse-open="{{loadDetails(data)}}">
{{data.Title}}
...
When I use the above code, the loadDetails function in polymer is not hitting.
Polymer('custom-item', {
data: {},
ready: function () {
},
loadDetails: function (e, details, sender) {
debugger;
}
});
If I am not using the function syntax in the declarative syntax(as below), the loadDetails function hits.
<core-collapse on-core-collapse-open="{{loadDetails}}">
{{data.Title}}
...
How can I send parameters in events.
on-core-collapse-open="{{loadDetails(data)}}"
This means: execute loadDetails(data) and whatever the return value of this is will be bound as the event handler. Not what you want.
Also, the event handler function already receives parameters: the event object. You cannot pass it additional parameters. If the data you want to pass refers to your this.data attribute: the loadDetails function already has access to it in the form of this.data, so you don't need to pass it.
If you're trying to use the same handler function for two different events and pass additional parameters with each individual event: traditionally you'd do that with an anonymous function wrapper, and that's simply not possible using the declarative syntax.
You can bind data to an attribute of core-collapse and then access the data using the target argument of the event handler or the target property of the event argument or alternatively if data is the model of the element anyway just access the TemplateInstance (see full example at https://stackoverflow.com/a/24530099/217408)
I got the answer from my another post. Even though I posted for different context, I understand I can use the same. Thanks Gunter for reply on that thread.
Polymer event parameters on repeat

How to trigger ValueChangeListener on the vaadin table?

The problem is, I cannot find listeners having been added to the table.
It seems the method getListeners doesn't work properly. It returns an empty collection.
My code:
table.addValueChangeListener(new MyListener());
System.out.println("ListenerCount="+table.getListeners(ValueChangeListener.class).size());
Console output:
ListenerCount=0
What is wrong? I expected it would return 1.
AbstractComponent.getListeners takes the event type class as an argument.
Pass it a Property.ValueChangeEvent or one of it's implementations, a Field.ValueChangeEvent or Label.ValueChangeEvent, depending on your use case.
If you read the API very carefully you'll see that you need to provide the event type of your listener:
java.util.Collection<?> getListeners(java.lang.Class<?> eventType)
Returns all listeners that are registered for the given event type
or one of its subclasses.
In your case:
table.getListeners(ValueChangeEvent.class);

Angularjs Directive Delegate not firing through intermediary handler

I have just spent 4 hours trying to implement a directive with a delegate, with no luck.
Use Case:
I have a directive called "filter".
When the user activates/deactivates the filters the parent scope may want to update the data on the screen.
Before I let the parent run, i want to make some internal changes to an internal data structure and pass the new filter state through to the parent.
I have created a jsfiddel to show a simplified version of what i am trying to do.
http://jsfiddle.net/concept/zADNy/
Here is my scope in the directive
scope : {
onFilterChanged : '&'
},
Here is the intermediary handler
function notifyParent() {
scope.onFilterChanged({filters:scope.filters});
}
Directive Delegates are must be lower case (someone please correct me if that statment is wrong, and if so, then why did the camel case version not work)
Ok so after hours of playing and reading and looking at other people's code, i found out that for some reason the delegate functions need to be lowercase.
Here is the resulting fix
http://jsfiddle.net/concept/zADNy/4/
Here is my scope in the directive
scope : {
onfilterchanged : '&'
},
Here is the intermediary handler
function notifyParent() {
scope.onfilterchanged({filters:scope.filters});
}

How can I remove an addCallback?

I have a Flash game which send and receive lot of messages from JavaScript.
Sometimes I need to stop listening some of those functions, but ExternalInterface doesn't have a removeCallback function. So I'm doing somthing ugly: using a boolean to validate if a callback is available in each function.
Any better solution?
ExternalInterface.addCallback("callAlert", callAlert);
function callAlert(msg:String){
if(callAlertAvailable){
//...
}
}
Just call again addCallback, setting the function as null:
ExternalInterface.addCallback("callAlert", null);
Why not read the docs? I found it here:
ExternalInterface.addCallback()
Note: Repeating addCallback() on an existing callback function with a
null closure value removes the callback.