2015년 1월 6일 화요일

Re: [AngularJS] grouped select/options from nested data

hi i would like to select parent node into dropdown. Like group is also selected..

On Saturday, 4 May 2013 03:38:17 UTC-7, Sylvain Robez-Masson wrote:
I found a solution : http://jsfiddle.net/vDdG2/5/

Le vendredi 3 mai 2013 09:40:39 UTC+2, Sylvain Robez-Masson a écrit :
I don't see any solution with ng-switch.
Maybe something like that : http://jsfiddle.net/vDdG2/2/
But obviously that doesn't work.

Le jeudi 2 mai 2013 18:17:02 UTC+2, Charles Kilbourne a écrit :
Sylvain you may want to use an ng-switch in your template, if you want an example set up a plunk and I'll try to help you out

On Thursday, May 2, 2013 11:14:30 AM UTC-4, Sylvain Robez-Masson wrote:
My problem is different, my data looks like this :
var categories = [
    {"id":"Cart","name":"Ma commande"},
    {"id":18,"name":"Menus"},
    {"id":14,"name":"Entr\u00e9es"},
    {"id":5,"name":"Plats","items":[
        {"id":7,"name":"Viandes"},
                {"id":8,"name":"Poissons"},
                {"id":11,"name":"Pizzas"}]
        },
        {"id":15,"name":"Desserts"},
        {"id":17,"name":"Boissons","items":[
                {"id":1,"name":"Alcoolis\u00e9es"},
                {"id":3,"name":"Sans alcool"}]
        }
]

Entries without items should be <option>, Entries with items should be <optgroup> and the items of the entry must be <option> of <optgroup>
How can I achieve that ?

Le mercredi 17 avril 2013 07:49:13 UTC+2, Peter Stephens a écrit :
Thanks Danny - exactly the problem I was struggling with....

Pete.

On Tuesday, 12 March 2013 10:29:01 UTC+8, Danny wrote:
Thanks Clint... that was helpful.

I have also found another way to do it... obvious really, just was distracted by the complexities of Angular.  

For those interested, the new solution:

    <select ng-model='theModel'>
      <option value='choose...'>Choose...</option>
      <optgroup ng-repeat='group in theList' label="{{group.group}}">
        <option ng-repeat='veh in group.items'>{{veh}}</option>
      </optgroup>
    </select>


Danny


댓글 없음:

댓글 쓰기