How to set Pre selected data in dynamic select option in IONIC
Asked Answered
A

1

0

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 Data

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

Athlete answered 19/12, 2016 at 13:45 Comment(0)
L
0

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.

Try to use like that:

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

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>

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

Latanya answered 21/12, 2016 at 9:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.