我在Ionic2中的变量中创建一个数组:
allMonths = {'01':'January','02':'February','03':'March','04':'April','05':'May','06':'June','07':'July','08':'August','09':'September','10':'October','11':'November','12':'December'};
我想全天获得(指定密钥)我在html中显示它们:
<ion-item>
<ion-select [(ngModel)]="allMonths">
<ion-option value="{{months.key}}" *ngFor = "let months of allMonths | keys">{{months.value}}</ion-option>
</ion-select>
</ion-item>
**我得到了回应,但问题是我得到了:
1日:十月第二:十一月第三:十二月第四:一月。。。12日:9月
*****,但我希望他们在弹出窗口中从Jan到Dec进行系列。
任何身体都可以建议我错了。
预先感谢。
After a long google I solved it as:
allMonths:Array<Object> = [
{id: '01', text: 'January'},
{id: '02', text: 'February'},
{id: '03', text: 'March'},
{id: '04', text: 'April'},
{id: '05', text: 'May'},
{id: '06', text: 'June'},
{id: '07', text: 'July'},
{id: '08', text: 'August'},
{id: '09', text: 'September'},
{id: '10', text: 'October'},
{id: '11', text: 'November'},
{id: '12', text: 'December'},
];
In Html:
<ion-item>
<ion-select [(ngModel)]="allMonths">
<ion-option value="{{months.id}}" *ngFor = "let months of allMonths ">{{months.id}}</ion-option>
</ion-select>
</ion-item>
希望它对某人有帮助。