Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在http本机get方法typescript上传递参数数组列表_Javascript_Angular_Typescript_Ionic Framework - Fatal编程技术网

Javascript 在http本机get方法typescript上传递参数数组列表

Javascript 在http本机get方法typescript上传递参数数组列表,javascript,angular,typescript,ionic-framework,Javascript,Angular,Typescript,Ionic Framework,我正在尝试传递数组列表参数。参数codeList包含类似数组的 [ { "projCode": "11-1115", "cblTagNo": "571_GE001-RC1" }, { "projCode": "11-1115", "cblTagNo": "571_GE001-S" } ] 但是我面临错误“无效的params对象,需要是带字符串的对象”。我可以知道如何通过obj阵列吗。 这是我的http调用方法 checkCableTagList(

我正在尝试传递数组列表参数。参数
codeList
包含类似数组的

[
  {
    "projCode": "11-1115",
    "cblTagNo": "571_GE001-RC1"
  },
  {
    "projCode": "11-1115",
    "cblTagNo": "571_GE001-S"
  }
]
但是我面临错误
“无效的params对象,需要是带字符串的对象”
。我可以知道如何通过obj阵列吗。 这是我的http调用方法

checkCableTagList(codeList: String[]){
  this.http.setDataSerializer('json');
  console.log(JSON.stringify(codeList));
  return this.http.get('http://hostname/cable/v2/cableschedule/key/', codeList, {});
}
我试过这种方法,但效果不太好

return this.http.get('http://hostname/cable/v2/cableschedule/key/', JSON.stringify(codeList), {});

您可以使用
HttpParams
发送此数组

   let httpParams: HttpParams = new HttpParams();
   codeList.forEach(code => httpParams = httpParams.append('Projects', code ));

 //Http request-
 return this.http.get('http://hostname/cable/v2/cableschedule/key/', {
   params: HttpParams 
 }).subscribe(
   (response) => //some manipulation with response 
 );

您是在typescript中使用httpClient还是仅使用http?您的
codeList
是一个对象数组,而不是字符串数组。这会产生将数组添加到
checkCableTagList
函数时看到的错误。我更改了post方法,而不是使用get方法。现在可以了。