setResult

Page

Sets the result data to send to the parent page. The framework passes this result to the parent page on close of the page. The parent page can get the result in the function registered using $m.onResult().

$m.setResult(result);

Syntax

        $m.setResult(result)

Parameters

result

string/number/boolean/object (required)

The result to be sent to the parent page.

Remarks

Apps generally involve multiple pages and hence a requirement of data exchange between pages arises. Following are the ways to share data between pages;

  1. Preferences

Data that has to be shared between pages can be stored into preferences. The pitfall in using preferences is that preferences get persisted and the developer should take responsibility of clearing the preferences data when done. Else, data sharing can pose a risk of unnecessary content eating up the device memory.

  1. Page data and result

The page methods below can be used to share data between pages,

  1. open - Helps to pass data to a child page.
  2. setResult - Helps to return data to the parent page.

The advantage of using these page methods is that they don’t persist the data and hence are suitable for any transient data.

However, the size of the result passed back to the parent page should be lesser to avoid any degradation in user experience as huge data would consume time and memory to process.