如何在IONIC中的动态选择选项中设置预选数据 [英] How to set Pre selected data in dynamic select option in IONIC

查看:273
本文介绍了如何在IONIC中的动态选择选项中设置预选数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个奇怪的问题,我需要在选择选项中显示Pre选择的数据(它也来自服务器)。我需要显示的选项基于键和值选项的选项的问题。

I face a strange problem where I need to show Pre selected data(which also come from server) in select option. The problem that I need to show select option based on key and value option.

       <div class="list list-inset">
            <span class="input-label">Permisstion</span>
            <select ng-model="permisstion" >
             <option ng-repeat="(key, value) in Roles" id="{{key}}" value="{{value}}">{{value}}</option>
            </select>
        </div>

JSON数据

"Roles": {
        "21": "Admin",
        "22": "Main Manager",
        "23": "Branch Manager",
        "26": "Side Manager"
    }

在选择选项中显示预选数据,我尝试了很多,但到现在我没有成功。
请帮助。

I don't no how to show Pre selected data in select option and I try a lot but till now I don't get success. Please help.

推荐答案

Firt,你的JSON不是一个对象数组。我不知道是否工作在< select> by objects atributes ...通过我的其他答案,你可以做类似下面的事情。

Firt, your JSON is not a array of objects. I dont know if work in a <select> by objects atributes... by my other answer you can do something like in below.

尝试使用像这样:

"Roles" : {
           [
              {code: 21, name: "Admin"},
              {code: 22, name: "Main Manager"}, 
              {code: 23, name: "Branch Manager"},
              {code: 24, name: "Side Manager"}
           ]
          }

因此,属性代码将是我对select:

So the atribute "code" will be my index to the select:

<select ng-options="role.name for role in Roles track by role.code">
        <option value="">They see me rollin</option>
</select>

我所做的是使用track by role.code,你可以在 video

What I do was use track by role.code, as you can watch in this video.

请记住:如果代码重新在对象数组中,它会破坏<选择>

REMEMBER: If code reapet in the array of objects it will break the <select>.

这篇关于如何在IONIC中的动态选择选项中设置预选数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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