angular - 如何禁用自动键值排序Angular 6
问题描述
我在我的 ts 文件中创建了数组,并使用 ngFor 从数组中获取元素,但是当我使用键值时,角度会自动对数组进行排序。创建了如何保存类似数组的订单。
TS代码:
filterListingTypeItems: { [key: string]: object } = {
'For sale': [
'For sale',
'By Agent',
'By ownre',
'New Construction',
'Foreclosures',
'Coming Soon',
],
'Potential listings': [
'Potential listings',
'Foreclosed',
'Pre-Foreclosure',
'Make Me Move',
],
'For Rent': ['For Rent'],
'Recently sold': ['Recently sold'],
_________________________: ['Open House only', 'Pending & Under Contract'],
}
HTML代码(角度材料):
<mat-optgroup
*ngFor="let listingOptions of (filterListingTypeItems | keyvalue)"
[label]="listingOptions.key"
>
<mat-option
*ngFor="let listingOption of listingOptions.value"
[value]="listingOption"
>{{ listingOption }}</mat-option
>
</mat-optgroup>
解决方案
您可以在组件 ts 文件中创建一个返回 0 的函数。
function returnZero() {
return 0
}
模板文件内部
<td *ngFor="let item of cfValues | keyvalue : returnZero">
推荐阅读
- typescript - 符号是什么意思| 在打字稿中?
- c# - C#如何在while循环中从另一个类调用void方法
- javascript - 使用 useContext 从数组中查找更新对象
- git - Ubuntu git pull 合并选项
- android - Android:Gradle build 不断拉下最新的 NDK 版本,而不是使用已经安装的版本
- python - 使用 Django Channels 立即发送消息
- java - Java - MongoDB 通过多个查询获得第一个结果的最佳方式
- reactjs - useEffect 不更新状态
- date-range - 如何在日期范围选择器上设置所选开始日期和结束日期之间的最短天数?
- css - 如何将两个模块并排放置在divi的同一列中?