Ionic2中包含自定义索引的数组 [英] Array with custom indexes in Ionic2

查看:115
本文介绍了Ionic2中包含自定义索引的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ionic2中的变量中创建一个数组:

I am creating an array in a variable in Ionic2 as:

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中:

I want to get all months (with keys specified) i am displaying them in html as :

<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>

**虽然我收到回复但问题是我得到的:

** Although i am getting response but the issue is i am getting as:

1st:October
2nd:November
3rd:December
4th:January



12th:September

1st: October 2nd: November 3rd: December 4th: January . . . 12th: September

*****但是我希望它们能够在jan到dec中弹出系列。

***** But i want them to be in series from jan to dec in popup.

任何机构都可以建议我在哪里错。

Can any body suggest please where i am wrong.

提前致谢。

推荐答案

    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>

希望它有所帮助。

这篇关于Ionic2中包含自定义索引的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆