function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Xiao LiuXiao Liu 

Is it able to create many <a></a> dynamically and binding onclick event to them?

In Component Contoller, is it able to create muliple <a></a> elements dynamically, and can we bind an existing function (which is in Controller ) to their onclick event?
Xiao LiuXiao Liu
Hi MithunP

    Thanks for your answer. 

    And I have tried Javascript yesterday, seems everything is OK but $A.enqueueAction(action) is not working fine in binding function.

    Within a single Javascript function, for example:
    
clickButton1 : function(component, event, helper) {
        var a = component.get("c.HelloWorldEcho");
        a.setParams({ "firstName" : component.get("v.firstName") });       
        a.setCallback(this, function(action) {
            if (action.getState() === "ERROR") {
                alert("Server Error: " + action.getError()[0].message);
            }
            else{
                alert("From server [ " + action.getReturnValue() + "]"); 
            }
        });
        $A.enqueueAction(a);
    },

     $A.enqueueAction(a);  can execute immediately and invoke the callback function.

    However, when I put $A.enqueueAction(a); into a binding function, for example:

testBind: function(component, event, helper) {
        var elem = document.getElementById("bindme");
        elem.onclick=function(e) {
            alert("binding successfully");                         
            var a = component.get("c.HelloWorldEcho");
            a.setParams({ "firstName" : "test name" });       
            a.setCallback(this, function(action) {
                if (action.getState() === "ERROR") {
                    alert("Server Error: " + action.getError()[0].message);
                }
                else{
                    alert("From server [ " + action.getReturnValue() + "]"); 
                }
            });
            $A.enqueueAction(a);
       };
},

in this case, $A.enqueueAction(a); is executed but not run immediately, seems this Action is blocked in queue untl next Action is insered.

Or, do we have a method to enforce runing Action after calling $A.enqueueAction()?

Thank you