我有一个列表unmentioned_colors = ["red", "green", "blue", "yellow"]
如果我提到多种颜色,我想更新我的unarched_colors数组,删除我提到的那些。因此,如果我写“红绿”,我想将它们从未提及的颜色中移除,它将成为[“蓝色”,“黄色”]
我试过了
untioned_colors = "<? $unmentioned_colors.removeValue(@colors.values) ?>"
但它没有用。
如何从数组中删除多个@colors?
答案 0 :(得分:0)
Watson Assistant支持two methods to remove an item from a JSONArray,删除(使用索引)和removeValue(使用值)。每种方法都只删除一个元素。因此,您需要循环/遍历要删除的元素,然后调用该方法。你能在应用程序中处理这个吗?
另一种方法是研究SpEL (the expression language)并使用集合选择/投影。
答案 1 :(得分:0)
要从@colors
删除所有$unmentioned_colors
项,应设置上下文变量$_bool_listchanged
,如下所示:
_bool_listchanged = "<? $unmentioned_colors.removeAll(@colors.values) ?>"
。
此解决方案不需要循环并且有效,因为在引擎盖下Watson Assistant使用Java来操作联系人中的项目。所以在这个数组上我们有方法removeAll,我们可以从Java调用它。