Page 1 of 1

Is there a way to set event using javascript?

Posted: Sun Apr 05, 2015 1:15 am
by Andrey Koposov

Can't find any method to set event to the object by javascript. The object appears after executing request, so it is not possible to set via graphic redactor.


Is there a way to set event using javascript?

Posted: Sun Apr 05, 2015 2:13 am
by M&M

Can you explain what you exactly mean? If the object is created after executing a request, you can add events to the object - either by jQuery or javascript. If you explain it a bit further perhaps I can help


Is there a way to set event using javascript?

Posted: Sun Apr 05, 2015 12:48 pm
by Andrey Koposov

If user does a request to database, the application gets array of items, which is needed to represent as an list of buttons. Each button has an action by click. So I need a way to set that action. To represent the array as a list I use "mapping", which provides to create new items in the list. How to make that each new button has its own action? What are the names of this javascript methods such as to set event by click on the element?


Is there a way to set event using javascript?

Posted: Sun Apr 05, 2015 3:37 pm
by M&M

So it goes like this - You have a list component and on the list item you have a button. Then you have mapped things so that after you invoke the service it adds items dynamically to the list and along with that the buttons. So here's what you could do along with screenshots

What I am doing here is to invoke a service which adds list items / buttons...and in the success event - mapping, I am adding the click event to the element. The JS is shown at the bottom

Image

Image

Image

Image

The javascript itself is couple of lines. All it does in this case is to print the button id to the console, as shown in the picture

code
element.click(function(){
var id = this.id;
console.log("button: " + id);
});
/code


Is there a way to set event using javascript?

Posted: Sun Apr 05, 2015 4:55 pm
by Andrey Koposov

I see, thank you. Is "element" javascript or special papery object?


Is there a way to set event using javascript?

Posted: Sun Apr 05, 2015 5:01 pm
by M&M

Nope, it's just referring to the object, in this case it is the button


Is there a way to set event using javascript?

Posted: Mon Apr 06, 2015 3:17 pm
by Andrey Koposov

asa