<!DOCTYPE html>
<html>

<head>
<title></title>
</head>

<body>
<script src="dojo/dojo.js" data-dojo-config="async: true">
</script>
<button type="button" id="publish">Publish "some/topic"</button>
<div id="output">Nothing Yet...</div>
<script type="text/javascript">
require(["dojo/topic", "dojo/dom", "dojo/on", "dojo/domReady!"], function(topic, dom, on) {
//在此订阅,"some/topic" 在public 和 publish 的时候必须要相同,
var handler = topic.subscribe("some/topic", function(evt) {
dom.byId("output").innerHTML = "I recievid " + evt.Msg;
handler.remove(); //词句代码,加上只监听一次,下次不再监听
});
//点击发布
on(dom.byId("publish"), "click", function() {
topic.publish("some/topic", { Msg: "huchao" });
// body...
})
// topic.publish("some/topic", "one0", "two0"); // setTimeout(function() { // topic.publish("some/topic", "one1", "two1"); // });

});
// body...
</script>
</body>

</html>

05-11 20:48