Pregunta

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?

¿Fue útil?

Solución

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).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top