to define a setter function, we create a function with the name:
_set<PropertyName>Attr: function(newValue) {
…
}
The property name within the function should be defined with an initial upper case.
Dojo Publish and Subscribe
Dojo provides a publish and subscribe mechanism where events can be published and subscribers
can register to be informed when an event is published. This provides very loose coupling between
producers of information and consumers.
Dojo provides a package called "dojo/topic" which is commonly bound to "topic".
To subscribe to a topic, we can use:
topic.subscribe("topic", function(data) {…});
To publish on a topic, we can use:
topic.publish("topic", data);
The following is pre Dojo 1.8 and can be removed later:
AMD: dojo/_base/connect → connect
To publish, we execute
connect.publish(Event Name (String), Event Message (optional);
Subscribers can register using
handle = connect.subscribe(Event Name (String), function(Event Message) { … });
alternatively, a JavaScript context (eg. this) can also be provided:
handle = connect.subscribe(Event Name (String), this, function(Event Message) { … });
The subscribe() method returns a subscription handle that can later be used to unsubscribe
using:
connect.unsubscribe(handle);
Dojo Charting
Dojo has the ability to draw various chart styles.
The Dojo charting package lives in the Dojo module called "dojox.charting.Chart2D".
At a high level, we create a <div> screen area with a width and height. This is the area into which
the chart will be drawn. An example of creating such a <div> would be:
<div id="myId" style="width: 250px; height: 150px;"></div>
Once created, when the page is loaded, we can then create a chart attached to this <div>
var chart1 = new dojox.charting.Chart2d("myId");
Notice that the parameter to the chart is the DOM id of the div.
Another way to create a chart is to be declarative. Here we can use:
<div data-dojo-type="dojox/charting/widget/Chart"
style="width: 400px; height: 400px;"
data-dojo-attach-point="_chart">
</div>
Page 206
Comentários a estes Manuais