Brian
Brian

Reputation: 2800

dojox.mobile.ListItem OnClick not working

I am trying to call a function when a ListItem is clicked in a dojo mobile application.

This is the function that programatically creates the ListItems

showResults : function(results) {

    results.forEach(function(result) {

        var li = new dojox.mobile.ListItem({
            class : "linklist",
            href : "#",
            label : result.address,
            moveTo : "#",
            clickable : true,
            onClick : function() {
                console.log("click");
            }
        }, domConstruct.create("li", null, this.searchList));

        // dojo.connect(li, "click", lang.hitch(this, this.addResult, result))

    }, this);

}

I have tried providing the function with the onClick property in the constructor, as well as using dojo.connect after creation. Neither way works. I've also tried different variations of click, onClick, and onclick.

Any other posts that I have seen regarding this issue have suggested using the dojo.connect method commented above, but that is still not working for me.

Any suggestions?

Upvotes: 0

Views: 1857

Answers (1)

edurocher
edurocher

Reputation: 316

This is because your widget's startup() method is never called. You must either call li.startup() explicitly, or, instead of creating and passing a reference node to the ListItem constructor, you could use this.searchList.addChild(li) (this will also cause startup() to be called properly).

Upvotes: 2

Related Questions