我的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#中的代码,以及我发送给Alexa的JSON(部分)。
//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无法看到当前值,因此假定它为null并仅加1,但我不明白为什么。你们中有人知道该怎么做吗?