c# - 使用 observable 按字母顺序排序数据
问题描述
我正在使用 angular 8 和 asp.net 核心,所以我想在下拉列表中显示客户的姓名作为 api 服务的字母顺序,我找到了使用 observable 的唯一解决方案。还有其他方法可以实现吗?以及如何在 observable 中使用字母排序?
getAllcustomer() {
return this._http.get<any>(this.myAppUrl + '/api/users/getcustomer', {responseType: 'json'} )
.catch(this.errorHandler);
}
谢谢
解决方案
您可以映射响应:
getAllcustomer() {
return this._http.get<any>(this.myAppUrl + '/api/users/getcustomer', {responseType: 'json'} ).pipe(
// assuming this API call gives you all the customers as an array of strings.
map((response: any) => response.sort()),
)
.catch(this.errorHandler);
}
将此排序放入服务中是可选的,您也可以在组件本身中进行排序。
推荐阅读
- html - 如何在锁定模式下在手机上播放声音
- excel - Excel 365 vba - (取消)保护工作表会大大降低宏的速度
- python-3.x - 读取 xml 并定位 tiff 文件中的行
- c++ - WinHttpSetOption() 设置 TLSv1.2 失败,错误代码为 ERROR_INTERNET_INCORRECT_HANDLE_TYPE
- webforms - 查找类型的 WebForms 父控件
- python - 如何覆盖 Enum 类以返回成员值而不是成员对象?
- amazon-web-services - 如何在 CloudFormation 中设置 DynamoDB 读取一致性
- regex - Perl 在匹配哈希键时转义通配符
- git - 新鲜的 git checkout 没有拉下最近的提交
- azure-data-lake - 将路径文件夹输出到没有“ColumnName =”的 Data Lake Store