0

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>
Ultimate Gobblement
  • 1,851
  • 16
  • 23

2 Answers2

0

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

tik27
  • 2,698
  • 1
  • 16
  • 25
0

In addition to the answer above, an additional option would be the use of the "data-dojo-id" property. You add this to your declaration which will then create a global variable with the name supplied. This variable will be set to a reference to the declared widget.

For example:

<div data-dojo-type="dojox.mobile.SwapView" data-dojo-id="view1">

will create a variable called view1 that will hold a reference to the SwapView.

Kolban
  • 13,794
  • 3
  • 38
  • 60