Search code examples
javascriptdojotooltip

Loading data asynchronously to Dojo Tooltip's getContent()


Here is an example of using getContent to display Dojo tooltip based on the element the mouse hovers over:

require(["dijit/Tooltip", "dojo/query!css2", "dojo/domReady!"], function(Tooltip){
    new Tooltip({
        connectId: "myTable",
        selector: "tr",
        getContent: function(matchedNode){
            return matchedNode.getAttribute("tooltipText");
            // What if we want to load this asynchronously???
        }
    });
});

However this doesn't work if you try to load data asynchronously via getContent(). Does anyonw knows how this can be solved?


Solution

  • When you set 'async: true' in the data-dojo-config property, dojo loader will load modules asynchronously. This means only the modules that you require will be loaded, therefore you won't have dojo/* or dijit/* .

    If you were running into this issue on JsFiddle, all you need to do is to change the Framework & Extensions from 'onLoad' to 'No wrap - in < head>', so dojo loader is called in before require is. Here is an example. Please note the fiddle option:

    data-dojo-config="async:true"