2

我目前正在开发一个基于 IBM Watson 对话的聊天机器人。我正在努力从enginePower过滤器中取出钥匙。我需要在聊天中显示每个键。所以用户可以选择一个。

结构如下所示:

"filter": {
"enginePower": [{
            "key": "55",
            "text": "55 kW (75 PS)",
            "selectable": false
          },
          {
            "key": "65",
            "text": "65 kW (88 PS)",
            "selectable": false
          },
          {
            "key": "66",
            "text": "66 kW (90 PS)",
            "selectable": false
          },
          {
            "key": "81",
            "text": "81 kW (110 PS)",
            "selectable": false
          }]
}

提前致谢。

4

1 回答 1

0

Short answer:

Your key values are: <? T(String).join( ",", $filter.get('enginePower').![key] ) ?>

Broken down

$filter.get('enginePower')

This will return the enginePower as an array containing all your objects.

.![key]

This will return the "Key" field values as an array.

T(String).join( ",", XXX )

This will convert your array XXX into a comma delimited list.

So your final output will say:

Your key values are: 55,65,66,81

Just to add to this. You can only get a single key/value list. If you want to capture a value of a different attribute using a key lookup, then you need to loop.

So for example, start by setting a counter to 0. Then have your node check for $filter.enginePower.size() > $counter.

Within that node, you set "multiple responses" on. Then for the first condition you set $filter.enginePower[$counter].selectable == true. This will allow you to take action if that field is true.

After this you need to create a child node, and have the parent node jump to it. Within the child node response put <? $counter = $counter + 1 ?>. Lastly have the child node jump back to the parent node.

This will loop through the array. Warning! You can only loop 50 times before the loop will end. This is to stop potential endless loops.


Realistically though, you can easily solve all this by formatting the data correctly at the application layer.

于 2018-04-11T05:08:15.133 回答