对节点快速服务器的 Angular 7.x 查询被转换为字符对象数组
Posted
技术标签:
【中文标题】对节点快速服务器的 Angular 7.x 查询被转换为字符对象数组【英文标题】:Angular 7.x query to node express server is converted to an object array of characters 【发布时间】:2020-03-31 18:24:44 【问题描述】:我正在向 node express 服务器发送一个查询字符串。当我访问 req.query 属性时,它是一个字符数组,而不是普通对象或我发送的字符串。有什么想法吗?
已发送查询
const data = await this.cspCrudService.findOne(stringQuery);
服务
findAll(params: any): Promise<T[]>
THIS LINE BELOW WAS THE PROBLEM
const query = StringUtil.toMongoQueryString(params);
return this.httpClient.get<T[]>(`$this.url$this.endpoint/$query`).toPromise();
"位置[$regex]=^F&location[$options]=i"
req.query
"0":"l","1":"o","2":"c","3":"a","4":"t","5":"i","6":"o","7":"n","8":"[","9":"$","10":"r","11":"e","12":"g","13":"e","14":"x","15":"]","16":"=","17":"^","18":"F","19":"","20":"l","21":"o","22":"c","23":"a","24":"t","25":"i","26":"o","27":"n","28":"[","29":"$","30":"o","31":"p","32":"t","33":"i","34":"o","35":"n","36":"s","37":"]","38":"=","39":"i"
【问题讨论】:
你怎么寄的?插入Http请求的代码。 @MaihanNijat 在您请求代码后,我注意到了问题。我前段时间添加了“StringUtil.toMongoQueryString”函数并忘记了它在那里。删除后它起作用了。谢谢 【参考方案1】:我前段时间添加了一个“StringUtil.toMongoQueryString”函数进行测试,但忘记了它在那里。删除后一切正常。
【讨论】:
以上是关于对节点快速服务器的 Angular 7.x 查询被转换为字符对象数组的主要内容,如果未能解决你的问题,请参考以下文章