question

Jonas Weichenhain avatar image
Jonas Weichenhain asked

APL / Pager: access payload/data in onPageChanged

Hello, inside my Pager's onPageChanged I need access to the data/payload of the currently displayed element in order to decide whether to execute a certain command or not. Currently, this is not working, null is returned if I try:

...
"layouts": {
    "CustomPager": {
      "parameters": [
        {
          "name": "data",
          "default": []
        },
        {
          "name": "direction",
          "default": "vertical"
        }
      ],
      "item": {
        "width": "100%",
        "height": "100%",
        "type": "Frame",
        "items": {
          "type": "Pager",
          "data": "${data}",
          "width": "100%",
          "height": "100%",
          "navigation": "normal",
          "pageDirection": "${direction}",
          "id": "myPager",
          "onPageChanged":[
            {
              "type": "SpeakItem",
              "sequencer": "onPageChangedSpeaking",
              "componentId": "invisbleSpeechOuputText${event.source.value}"
            },
            {
               "type": "SendEvent",
               "delay": "${data.delay}",
               "arguments": [
                  "page:${data.number}"
               ]
            }
          ],
 ...

I do not simply need the current page index (I know that you can get it with event.source.value).

Do you know any solution to this problem or any workaround / suggestions to solve it?

alexa skills kitapl
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Alexander Martin avatar image
Alexander Martin answered

data is an array, you have to access the entry for the current page via the index:

data[event.source.value].number


for some inspiration you can check out this document https://apl.ninja/document/xeladotbe/an-infinite-loop-pager-component-with-lifecycle-events-c5we

1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks for your help, the binding and then accessing by index did the trick.

0 Likes 0 ·