I have a widget A that publishes data and two more widgets B and C. When B calls fetchData for widget A the onReceiveData events fire for both B and C. Is that supposed to happen? I would expect only B's onReceiveData event to fire since it is the one who called fetchData.
I don't think that will work for me. I would have to update listenWidgetIds property before every fetch to make sure only the caller is receiving the data. I want all my widgets to be able to get data from widget A but I only want a widget to receive the data if it is the source of the fetch call.
I'm just going to use the WidgetManager to get a reference to my A widget and then directly access properties that I set on it.
<SPAN class="keyword token">var</SPAN> widgets <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>appConfig<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getConfigElementsByName</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'MyWidget'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> widgetId <SPAN class="operator token">=</SPAN> widgets<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>id<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> myWidget <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>widgetManager<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getWidgetById</SPAN><SPAN class="punctuation token">(</SPAN>widgetId<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Access data of widget directly</SPAN> <SPAN class="keyword token">var</SPAN> data <SPAN class="operator token">=</SPAN> myWidget<SPAN class="punctuation token">.</SPAN>someProperty<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// use data...</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Joe,
In the BaseWidget.js file there is this:
//listenWidgetIds: String[] // app use this property to filter data message, if not set, all message will be received. // this property can be set in config.json this.listenWidgetIds = [];
Hmm still happens. Does it matter that C had called fetchData(someWidgetId) in the past before B calls fetchData(someWidgetId)? It seems C is now subscribed to receive data whenever a fetch is requested for A.
If you just do widget.fetchData(); the you get that result. But if you provide a widget ID in the fetchData(someWidgetId); then you can limit it.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.