Karate 如何在空手道中迭代普通数组?

Karate 如何在空手道中迭代普通数组?,karate,Karate,我的一个任务的输出是['a','b','c'] 现在我必须在DB查询中使用这些值 * def queryToGetHotelIdForAvailableCsId = "select id from hotels_hotel where cs_id in ('a','b','c');" 在空手道中如何做到这一点?使用Java助手可能会更好,但您可以这样做: * def json = ['a', 'b', 'c'] * def fun = """ function(array) { var

我的一个任务的输出是['a','b','c']

现在我必须在DB查询中使用这些值

* def queryToGetHotelIdForAvailableCsId = "select id from hotels_hotel where cs_id in ('a','b','c');"

在空手道中如何做到这一点?

使用Java助手可能会更好,但您可以这样做:

* def json = ['a', 'b', 'c']
* def fun = 
"""
function(array) {
  var temp = '';
  for (var i = 0; i < array.length; i++) {
    if (i > 0) temp = temp + ',';
    temp = temp + "'" + array[i] + "'"
  }
  return '(' + temp + ')';
}
"""
* def result = fun(json)
* match result == "('a','b','c')"
*def json=['a','b','c']
*def fun=
"""
函数(数组){
var temp=“”;
对于(var i=0;i0)温度=温度+',';
temp=temp+“'”+数组[i]+“'”
}
返回“(“+temp+”)”;
}
"""
*def result=fun(json)
*匹配结果==“('a'、'b'、'c')”