Проблема привязки данных комплекта Alexa Skills Kit - PullRequest
0 голосов
/ 19 октября 2019

У меня небольшая проблема с моим навыком Alexa. У меня есть компонент, который показывает количество элементов, и две кнопки, которые должны увеличивать (уменьшать) это значение. В соответствии с документацией этот код должен работать:

{
  "type": "TouchWrapper",
  "bind": [
    {
      "name": "MyCounter",
      "value": 0,
      "type": "number"
    }
  ],
  "item": {
    "type": "Text",
    "text": "You have pressed the button ${MyCounter} times"
  },
  "onPress": {
    "type": "SetValue",
    "property": "MyCounter",
    "value": "${value + 1}"
  }
}

У меня есть похожий код в моем приложении, но результат другой,

При первом нажатии кнопки (увеличение) значениеустановлен на 1. Каждый следующий клик ничего не делает. Вот мой код на C # и JSON (часть), который я отправляю в Alexa.

//Container for quantity

            Item quantity_container = new Item();

            quantity_container.Type = "Container";
            quantity_container.spacing = "30";
            quantity_container.Direction = "row";
            quantity_container.bind = new List<Bind>();
            Bind textNr = new Bind();
            textNr.name = "textNr";
            //textNr.value = "${secondaryText}";
            textNr.value = "0";
            textNr.type = "number";
            quantity_container.bind.Add(textNr);
            quantity_container.id = "${data.textContent.quantityId}";


            quantity_container.items = new List<Item>();

            main_container.items.Add(quantity_container);

            //Minus quantity

            //minus touch wrapper

            Item touch_wrapper_minus = new Item();

            touch_wrapper_minus.Type = "TouchWrapper";

            touch_wrapper_minus.onPress = new List<OnPress>();

            //Set value

            OnPress minus_set_value = new OnPress();

            minus_set_value.type = "SetValue";
            minus_set_value.componentId = "${data.textContent.quantityId}";
            minus_set_value.property = "textNr";
            minus_set_value.value = "${value - 1}"; //TODo

            touch_wrapper_minus.onPress.Add(minus_set_value);
touch_wrapper_minus.items = new List<Item>();

            quantity_container.items.Add(touch_wrapper_minus);

/* Other display elements */

//Quantity

            Item quantity_text = new Item();

            quantity_text.Type = "Text";
            quantity_text.Text = "${textNr}";
            quantity_text.Width = "10vw";
            quantity_text.Height = "10vh";
            quantity_text.textAlign = "center";

            quantity_container.items.Add(quantity_text);

И JSON

"type": "Container",
                                                "items": [
                                                    {
                                                        "type": "TouchWrapper",
                                                        "items": [
                                                            {
                                                                "type": "Frame",
                                                                "height": "50",
                                                                "width": "50",
                                                                "items": [
                                                                    {
                                                                        "type": "Text",
                                                                        "height": "50",
                                                                        "width": "50",
                                                                        "text": "-",
                                                                        "textAlign": "center"
                                                                    }
                                                                ],
                                                                "borderColor": "#ffffff",
                                                                "borderRadius": "9",
                                                                "borderWidth": "1"
                                                            }
                                                        ],
                                                        "onPress": [
                                                            {
                                                                "type": "SetValue",
                                                                "componentId": "${data.textContent.quantityId}",
                                                                "property": "textNr",
                                                                "value": "${value - 1}"
                                                            },
                                                            {
                                                                "type": "SendEvent",
                                                                "arguments": [
                                                                    "DecreaseByOne",
                                                                    "${data.textContent.id}"
                                                                ]
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        "type": "Text",
                                                        "height": "10vh",
                                                        "width": "10vw",
                                                        "text": "${textNr}",
                                                        "textAlign": "center"
                                                    },
                                                    {
                                                        "type": "TouchWrapper",
                                                        "items": [
                                                            {
                                                                "type": "Frame",
                                                                "height": "50",
                                                                "width": "50",
                                                                "items": [
                                                                    {
                                                                        "type": "Text",
                                                                        "height": "50",
                                                                        "width": "50",
                                                                        "text": "+",
                                                                        "textAlign": "center"
                                                                    }
                                                                ],
                                                                "borderColor": "#ffffff",
                                                                "borderRadius": "9",
                                                                "borderWidth": "1"
                                                            }
                                                        ],
                                                        "onPress": [
                                                            {
                                                                "type": "SetValue",
                                                                "componentId": "${data.textContent.quantityId}",
                                                                "property": "textNr",
                                                                "value": "${value + 1}"
                                                            },
                                                            {
                                                                "type": "SendEvent",
                                                                "arguments": [
                                                                    "IncreaseByOne",
                                                                    "${data.textContent.id}"
                                                                ]
                                                            }
                                                        ]
                                                    }
                                                ],
                                                "direction": "row",
                                                "spacing": "30",
                                                "id": "${data.textContent.quantityId}",
                                                "bind": [
                                                    {
                                                        "name": "textNr",
                                                        "value": "0",
                                                        "type": "number"
                                                    }
                                                ]
                                            }

Я думаю, что проблема в том, что TouchWrapper можеттекущее значение не отображается, поэтому предполагается, что оно равно нулю и просто добавляет 1, но я не могу понять, почему. Кто-нибудь из вас знает, что делать?

...