Widget Communication

1226
4
10-08-2016 12:41 AM
qiangyan
New Contributor

how I use "publishData" and "onReceiveData" .

I use the samplewidgets WidgetCommunication(WidgetA,WidgetB)

when I click publish Data ,there was a mistake.

error info

Does anybody have this working, and have any advice for me?

0 Kudos
4 Replies
qiangyan
New Contributor

code:

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Qiang,

Sure I have it working is several of my widgets.

In my eSearch widget I have a function like this (line 3):

      _initDrawBox: function () {
        aspect.before(this.drawBox, "_activate", lang.hitch(this, function(){
          this.publishData({message: "Deactivate_DrawTool"});
        }));

In my other widgets that I want to listen I have:

      startup: function(){
        this.inherited(arguments);
        this.fetchData();
        this.list.parentWidget = this;
      },‍‍‍‍‍

      onReceiveData: function(name, widgetId, data) {
        if(data.message && data.message === "Deactivate_DrawTool"){
          this.drawBox.deactivate();
        }
      },

If the widget is not open when the other widget publishes data then you have to call fetchData when the widget does start so that it looks for the data and calls the onRecieveData method.

I am not sure why you are having that error you are showing though.

qiangyan
New Contributor

thanks for your replay. it woks use your code.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.

0 Kudos