<\/HEAD>
In some cases, there is a requirement to access information from one widget in another widget. Then the question arises how to make the data from one widget available to another widget.<\/P>
For this use case, a widget has the functions publishData(), fetchData(), fetchDataByName(), onReceiveData(), and onNoData(). These functions are automatically inherited by a custom widget from BaseWidget.<\/P>
To better understand the use of these functions, let's look at a very simple example with two widgets. The
first widget named SetLocation is used to input an X\/Y coordinate to which the map can be centered:<\/P>
<\/P>
The second widget named GetLocation simply displays this X\/Y coordinate again:<\/P>
<\/P>
How do the coordinate values get into the second widget?<\/P>
In the widget that sends the data, i.e., SetLocation, the coordinate values are entered into two input fields and read out in a function
that is called by clicking the button. If you have multiple individual data points, you can combine them, for example, in a JSON string. To make this data available to other widgets, the function publishData() is called and the data is passed to it:<\/P>
<\/P>
In the widget that should receive the data, i.e., GetLocation, the data is retrieved with the function fetchData(widgetId).
The function can be called, for example, in the startUp() method:<\/P>
<\/P>
The parameter widgetId is the ID of the widget that sends the data (here SetLocation), as entered in the app's configuration file config.json
.<\/P>
If data is available for reception, it is provided in the event handler function onReceiveData(), which must be implemented in the receiving widget. If no data is available, the event handler function onNoData() is called.<\/P>
<\/P>
In the function onReceiveData(), the transmitted data is passed as a parameter so that it can be used here, e.g., to display it
in the widget.<\/P>
To summarize the process once again:<\/P>
1) In the sending widget, provide the data using the function publishData().<\/P>
2) In the receiving widget, query the data using fetchData() and read and use it in onReceiveData().<\/P>
<\/P>
Happy coding!<\/P><\/BODY><\/HTML>