Search code examples
javascripthtmldojodeclarative

How to obtain object references when using declarative Dojo


I'd like to know how to get an object reference when using Dojo with declarative HTML.

I have some code for sliding panel that I took from an example: http://demos.dojotoolkit.org/demos/mobileSlideShow/demo.html

In my version there are navigation buttons. dojox.Mobile.SwapView has a goTo method, which I should be able to use, but I can't figure out how to get the object reference I need to call the method from. In the example below, the object would be 'ref' - how can I obtain this reference?

<div class="panel" data-dojo-type="dojox.mobile.SwapView">
  <p>Some text..</p>
  <div class="next" onclick="ref.goTo(1)">Next</div>
</div>
<div class="panel" data-dojo-type="dojox.mobile.SwapView">
  <p>Some other text..</p>
  <div class="prev" onclick="ref.goTo(-1)">Prev</div>
</div>

Solution

  • You can do

    onclick="dijit.registry.byNode(this.parentNode).goTo(1)"
    

    or

    onclick="dojo.publish('/dojox/mobile/prevPage', dijit.registry.byNode(this.parentNode))"
    

    Not sure if there is a cleaner way