Widget: Finding the enclosing data view object

3
Within a widget we can use the context object. No problem. Microflow Buttons can also use the 'Pass enclosed data view object' (how do they do that?) How can I access the enclosed data view object from within the widget? There is an many to one relation * -> 1 for the enclosed data object to the data view where my object is in. So using Xpath retrieve to get the enclosed object is not an option. Please advice on how to solve this? thank you. Andries
asked
2 answers
4

There actually is a function to find the enclosing widget already in the dijit library.

var aWidget = dijit.getEnclosingWidget(e.target); // pass a domNode

You can check out http://dojotoolkit.org/reference-guide/1.9/dijit/getEnclosingWidget.html for the full documentation.

answered
1

Got something, but is there a better way?

 var enclosedContext = this.findEnclosedContext(this.domNode.parentNode);

 findEnclosedContext: function (node) {
    var count = 2;
    while (node) {
        if (node.tagName && node.tagName.toLowerCase() == "body") {
            return;
        } else {
            var id = node.getAttribute && node.getAttribute("widgetId"),
                widget = id && dijit.byId(id);
            if (widget) {
                count--;
                if (count === 0)
                    return widget.mxcontext;
            }
            node = node.parentNode;
        }
    }
},
answered